469,934 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

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

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


Nov 17 '05 #1
1 10284
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" <no****@yahoo.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
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


Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Daniel Walzenbach | last post: by
8 posts views Thread by SAL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.