From: Jonathan Wood on
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


From: Registered User on
On Sat, 15 May 2010 17:56:26 -0600, "Jonathan Wood"
<jwood(a)softcircuits.com> wrote:

>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.
From: Jonathan Wood on
"Registered User" <n4jvp(a)ix.netcom.com> wrote:

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

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


From: Registered User on
On Sun, 16 May 2010 08:55:01 -0600, "Jonathan Wood"
<jwood(a)softcircuits.com> wrote:

>"Registered User" <n4jvp(a)ix.netcom.com> wrote:
>
>>>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.
>
>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.