Re: Controls - Page_init order



Sorry.

Actually, the heading should be Controls - Page_Load order.

I can see where it may be confusing. I rewrote it slightly, so hopefully it
is more clear.

I have a control (PageInit.ascx) that I want to put in all my pages and have
it
execute only once during the "not IsPostback" section. I also need it to
execute first before anything else since it is initialization code. I don't
want it to run during postback. I want to place this controls on all my
pages. This will allow me to add code later on that I want to pertain to
all my pages without having to change all my pages.

I placed trace.warn statements to show me what the order of execution is.

I tried 2 ways and each way the trace.warn statement I put in the control is
the last trace statement I see, so I assume all the other code in the parent
page gets executed first then the Page_Load code from the control
(PageInit.ascx) gets executed. Not what I am trying to do.

1) I have the parent set as:

*********************************************
<%@ Register TagPrefix="fts" TagName="pageInit"
Src="/controls/pageInit.ascx" %>
....
<body>
....
<fts:pageInit runat="server"/>
************************************************

The whole .ascx file is:
************************************************

<script runat="server"> Sub Page_Load(sender as Object, e as EventArgs)
trace.warn("Inside PageInit.ascx") Dim UserLoggedOn as Label =
CType(Page.FindControl("UserLoggedOn"),Label) Dim UserLoggedOnLabel as
Label = CType(Page.FindControl("UserLoggedOnLabel"),Label) if not
UserLoggedOn is nothing then if session("LoggedIn") <> nothing then
if session("firstName") <> nothing then UserLoggedOn.Text =
UserLoggedOn.Text & session("firstName") if session("lastName") <>
nothing then UserLoggedOn.Text = UserLoggedOn.Text & " " &
session("lastName") end if end if if not UserLoggedOn is
nothing then UserLoggedOn.visible = true if not UserLoggedOnLabel
is nothing then UserLoggedOnLabel.visible = true end if end if end
if if not session("User") is nothing then session("LastPageVisited") =
Session("User").LastPageVisited End Sub </script>
**************************************************************

This works fine, except that the Page_Load function (from my control)
doesn't run until after all the Page_Load code has run.

2) I also tried loading the same .ascx file dynamically.

**************************************************
....
Sub Page_Load(sender as Object, e as EventArgs)
Dim sTest as String
trace.warn("UserID = " & session("User").UserID)
if not IsPostBack
Dim pageControl As Control = LoadControl("/controls/pageInit.ascx")
PageUserControl.Controls.Add(pageControl)
....
trace.warn("In Parent 1")
....
end if
trace.warn("In Parent 2")
....
End Sub
....
<body>

<asp:placeholder ID="PageUserControl" runat="server"/>
<form runat="server">
....

*******************************************

My trace will show as:

In Parent 1
In Parent 2
Inside PageInit.ascx

Is there a way to get my control to execute first and only once?

Thanks,

Tom.


"Juan T. Llibre" <nomailreplies@xxxxxxxxxxx> wrote in message
news:eQvEc0KwGHA.3936@xxxxxxxxxxxxxxxxxxxxxxx
re:
This works fine, except that the Page_Load function doesn't run until
after all the Page_Load code has run.

If it means anything, I'm puzzled by your statement, too.

Can you clarify ?





Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:efqhKtKwGHA.3372@xxxxxxxxxxxxxxxxxxxxxxx
"Mark Rae" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:uLW7FZKwGHA.1888@xxxxxxxxxxxxxxxxxxxxxxx
"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:uE91z5JwGHA.976@xxxxxxxxxxxxxxxxxxxxxxx

This works fine, except that the Page_Load function doesn't run until
after all the Page_Load code has run.

???
What?





.



Relevant Pages

  • Re: MFC and c++ problems
    ... You say that a control must make no assumptions about its parent. ... messages to its parent will compile and run ... ... One could write an interface class that supported the methodneeded by ...
    (microsoft.public.vc.mfc)
  • Re: Controls - Page_init order
    ... the control after the Page_Load. ... Parent that says "Inside the Parent Page_Load", ... e as EventArgs) Dim sTest as String trace.warn("Inside the ... execute first before anything else since it is initialization code. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Master Detail Event Handling?
    ... > Your example hides the child records unless the user clicks the parent row. ... > then use to identify the child control to work with the child control events. ... >>> Parent Record ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: MFC and c++ problems
    ... including CWinApp, CView, or CDialog classes that might contain it. ... You say that a control must make no assumptions about its parent. ... messages to its parent will compile and run ... ...
    (microsoft.public.vc.mfc)
  • Re: MFC and c++ problems
    ... assumption that its parent can handle that message? ... control says "here is something. ... if the control defines an interface in terms of message passing and the ... must inherit from an abstract class MyFancyWidgetUser. ...
    (microsoft.public.vc.mfc)