Page Load/Click Event Timing Issue


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
 
Ad

Advertisements

R

Registered User

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.
 
J

Jonathan Wood

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
 
Ad

Advertisements

R

Registered User

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top