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

Discussion in 'ASP .Net' started by Jason, Jun 10, 2004.

  1. Jason

    Jason Guest

    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?
     
    Jason, Jun 10, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    >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?
     
    Ken Cox [Microsoft MVP], Jun 10, 2004
    #2
    1. Advertising

  3. RE: Stopping further processing with an Exit Sub in the Page_Load Even

    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



    "Jason" wrote:

    > 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?
    >
     
    =?Utf-8?B?U3RldmUgSw==?=, Jun 10, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gopal Krish

    Stop further execution in Page_Load

    Gopal Krish, Oct 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    13,018
    Gopal Krish
    Oct 25, 2004
  2. Avi Kak
    Replies:
    4
    Views:
    376
    Avi Kak
    Feb 17, 2004
  3. rockdale
    Replies:
    1
    Views:
    665
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Nov 16, 2006
  4. Ben
    Replies:
    2
    Views:
    910
  5. Lawrence D'Oliveiro

    Death To Sub-Sub-Sub-Directories!

    Lawrence D'Oliveiro, May 5, 2011, in forum: Java
    Replies:
    92
    Views:
    2,062
    Lawrence D'Oliveiro
    May 20, 2011
Loading...

Share This Page