ASP.NET Postback Event Occurrs Again after page refresh

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
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
 
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
 
Back
Top