Page Load/Click Event Timing Issue

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

I have a webform that alters it's content depending on whether or not the
current user is logged in. It does this in the Page_Load event.

My master page has a logout button. If the user clicks this button, it fires
the Page_Load event in my content page, the Page_Load event in my master
page, and finally the Logout_Click event for my logout button.

This means that my code that alters the page (depending on whether or not
the current user is logged in) fires before the code that logs the user out.
This results in serving a page for a logged-in user when they are now logged
out.

I'm not sure how best to handle this. My page has a lot of initialization
code that I do not want to run twice. If it's a postback, I need to delay my
initialization code somehow until after the Logout_Click event has executed
on the master page.

I welcome any helpful suggestions.

Jonathan
 
I have a webform that alters it's content depending on whether or not the
current user is logged in. It does this in the Page_Load event.

My master page has a logout button. If the user clicks this button, it fires
the Page_Load event in my content page, the Page_Load event in my master
page, and finally the Logout_Click event for my logout button.

This means that my code that alters the page (depending on whether or not
the current user is logged in) fires before the code that logs the user out.
This results in serving a page for a logged-in user when they are now logged
out.

I'm not sure how best to handle this. My page has a lot of initialization
code that I do not want to run twice. If it's a postback, I need to delay my
initialization code somehow until after the Logout_Click event has executed
on the master page.
The Page type's IsPostback property is self-descriptive.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// intialization code
}
}

regards
A.G.
 
Registered User said:
The Page type's IsPostback property is self-descriptive.

Yes it is. But it escapes me how that helps me delay my initialization code
somehow until after the Logout_Click even has executed on the master page.
Moreover, this issue comes up on several content pages. I was hoping for
some sort of solution on the master page.

Jonathan
 
Yes it is. But it escapes me how that helps me delay my initialization code
somehow until after the Logout_Click even has executed on the master page.

How many times should a page instance be initialized? I think what you
want to do is load a new instance of the page from the Logout_Click
event handler. This can be done with a Server.Transfer or
Response.Redirect call.
Moreover, this issue comes up on several content pages. I was hoping for
some sort of solution on the master page.
It's not a bad idea to use the IsPostback member in any page's
Page_Load handler where there is initialization code.

regards
A.G.
 
Back
Top