How can I prevent a button event firing on page refresh?

Discussion in 'ASP .Net' started by Stan, Jun 27, 2003.

  1. Stan

    Stan Guest

    If a page has a button with event handler

    private void btnAdd_Click(object sender, System.EventArgs e)
    {
    .......
    }

    this event handler fires every time I refresh the page in the browser with
    F5 AFTER
    the button was clicked.

    So the pages loads the first time.
    clicking F5 does normal postback and refresh
    Add button clicked, btn_Add_Click is called
    Now if I click F5 btn_AddClick is called again...

    If there two buttons on the page, whichever was clicked last will be
    executed again on F5.

    How can I stop it?

    Thanks,

    -Stan
     
    Stan, Jun 27, 2003
    #1
    1. Advertising

  2. Skip smart navigation. It only sometimes works.

    Put information about the type of event fired into the session object when
    the event fires the first time.
    In the same event handler read this value from the session if it differes
    then it means that you've clicked a different button and you should run the
    event. If it doesn't then it means you've clicked on the same button two
    times and that you should ignore the event. Works good, assuming that you
    don't want to fire the same event in concession.

    "Stan" <> wrote in message
    news:...
    > If a page has a button with event handler
    >
    > private void btnAdd_Click(object sender, System.EventArgs e)
    > {
    > ......
    > }
    >
    > this event handler fires every time I refresh the page in the browser with
    > F5 AFTER
    > the button was clicked.
    >
    > So the pages loads the first time.
    > clicking F5 does normal postback and refresh
    > Add button clicked, btn_Add_Click is called
    > Now if I click F5 btn_AddClick is called again...
    >
    > If there two buttons on the page, whichever was clicked last will be
    > executed again on F5.
    >
    > How can I stop it?
    >
    > Thanks,
    >
    > -Stan
    >
    >
    >
    >
    >
    >
     
    Tomasz Kaszuba, Jun 30, 2003
    #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. Alan Silver
    Replies:
    4
    Views:
    535
    Alan Silver
    Jul 20, 2005
  2. APA
    Replies:
    2
    Views:
    678
  3. GauravGupta
    Replies:
    4
    Views:
    2,146
    Shilpa1234
    Jan 19, 2012
  4. archana

    Page Refresh firing event twice

    archana, Oct 26, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    760
    archana
    Oct 27, 2007
  5. Andy
    Replies:
    1
    Views:
    345
    Mike Brind
    Dec 1, 2006
Loading...

Share This Page