How to stop control events from firing in Page_Load

Discussion in 'ASP .Net' started by Ahmet Gunes, Jun 19, 2005.

  1. Ahmet Gunes

    Ahmet Gunes Guest

    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
    Ahmet Gunes, Jun 19, 2005
    #1
    1. Advertising

  2. Ahmet Gunes

    Norman Yuan Guest

    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.

    "Ahmet Gunes" <> wrote in message
    news:...
    > 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
    >
    >
    >
    Norman Yuan, Jun 19, 2005
    #2
    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. C K
    Replies:
    2
    Views:
    3,728
  2. Replies:
    3
    Views:
    1,938
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 30, 2006
  3. Randy

    Events fire and then stop firing

    Randy, Dec 6, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    338
    Randy
    Dec 6, 2006
  4. mark4asp
    Replies:
    3
    Views:
    595
    Mark Rae
    Mar 8, 2007
  5. SevDer
    Replies:
    2
    Views:
    1,296
    Walter Wang [MSFT]
    Nov 13, 2007
Loading...

Share This Page