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

  • Thread starter Thread starter Stan
  • Start date Start date
S

Stan

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
 
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.
 
Back
Top