Stopping further processing with an Exit Sub in the Page_Load Event not working.

J

Jason

I have an ASP.NET page that needs to use values set in session
variables to perform certain functions. I have code in the Page_Load
event that makes sure the session has not been restarted:

If Session.IsNewSession Then
Response.Write("<script>alert('Your session has
expired.');window.close();</script>")
Exit Sub
End If

This code does catch a "new" session, but processing continues if a
button has been clicked on the page to that event handler. Therefore,
I'm still getting an application error when that function is looking
for session variables that are now equal to nothing. Is there some
function other than Exit Sub that will stop all further processing if
a condition is met from the Page_Load event?
 
K

Ken Cox [Microsoft MVP]

Not sure, but if a routine is looking for a Session variable that hasn't
been set yet, you might be able to trap it like this:

If Session("variablename") is Nothing then
exit sub
End if
 
G

Guest

Jason - Have you tried just doing a Response.Redirect to send them to another page? If you want to stop the output at that point I believe you can use Response.end
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top