ASP.NET Postback Event Occurrs Again after page refresh

G

Guest

Hi. If an ASP.NET page postsback, for example, after a button is clicked,
and then I refresh the page (ie, by pressing F5 key), why does the same event
occur when I press F5 as it did when I clicked the button?

For example - On an ASP.NET webform I click a button which produces a
postback and a Button.Click event. After the postback, I press F5 to refresh
my webform, which executes Button.Click again.

Is there a way to prevent the same event from firing again if a page refresh
occurrs?
 
G

Guest

When you refresh the Page, the browser is dutifully reproducing the last
action, which was an HTTP POST.

There are a number of ways to prevent this; a simple one is simply to set a
session variable to indicate the page was posted, the first time. On
subsequent posts you would check this Session item to see if the page has
already been posted, and if so, abort the action.
Peter
 
G

Guest

Thank you for that information!

Peter Bromberg said:
When you refresh the Page, the browser is dutifully reproducing the last
action, which was an HTTP POST.

There are a number of ways to prevent this; a simple one is simply to set a
session variable to indicate the page was posted, the first time. On
subsequent posts you would check this Session item to see if the page has
already been posted, and if so, abort the action.
Peter
 
A

Anna

Hi,
I am trying to build an ASP.Net Web Part which contains a ListBox control and a Button control. The problem is that if I do a refresh of the page where the eventhandler for the button is triggered. I only want this to trigger when I actually click the button. How can I accomplish this? I instantiate the button and adds the click event handler in the CreateChildControls()-method.

From http://www.developmentnow.com/g/8_2...ack-Event-Occurrs-Again-after-page-refresh.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top