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

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
 
T

Tomasz Kaszuba

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top