How to stop control events from firing in Page_Load

A

Ahmet Gunes

Hi all,

[I am sure it's a simple question to most of you :)]

I check whether session is alive in Page_Load.
If session is not alive then I want to navigate to another page, most
probably the login page.
But when a control, a button for example, is clicked, after Page_Load the
button's click event is also fired.
Since session is abandoned at this moment, any object references raise
"object reference not set" exception.

Since my application contains frames I do not use Server.Transfer or
Response.Redirect. In stead, I use client side javascript code to navigate
to the login page in the "top" window.

What's the workaround of this situation?

thanks in advance,

AG
 
N

Norman Yuan

You cannot stop event firing, it is biult into the page processing. You can
choose not handling or handling correctly (in your case).

For example, your problem could be the user click a button after a long
pause so that the session has been timed out. You simply:

private Button1_Click(....)
{
if (Session["MyObject"]==null)
{
Response.Redirect("OtherPage.aspx");
return;
}

//Do regular buton-click handling
}

BTW, if you wnat to redirect user to a loggin page, why not using Form
authentication, which automatically handles loggin redirecting for you if
session is timed out.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top