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

  • Thread starter Thread starter Jason
  • Start date Start date
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?
 
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
 
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
 
Back
Top