Re: Controls - Page_init order
- From: "tshad" <tscheiderich@xxxxxxxxxxxxxxx>
- Date: Tue, 15 Aug 2006 14:15:22 -0700
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 messageWhat?
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.
???
.
- Follow-Ups:
- Re: Controls - Page_init order
- From: tshad
- Re: Controls - Page_init order
- References:
- Controls - Page_init order
- From: tshad
- Re: Controls - Page_init order
- From: Mark Rae
- Re: Controls - Page_init order
- From: tshad
- Re: Controls - Page_init order
- From: Juan T. Llibre
- Controls - Page_init order
- Prev by Date: Re: Wiki suggestions
- Next by Date: Re: DataGridItemEventArgs and Hyperlinkcolumn
- Previous by thread: Re: Controls - Page_init order
- Next by thread: Re: Controls - Page_init order
- Index(es):
Relevant Pages
|