By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

ASP.NET Postback Event Occurrs Again after page refresh

P: n/a
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?
Apr 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mike" wrote:
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?
Apr 30 '07 #2

P: n/a
Thank you for that information!

"Peter Bromberg [C# MVP]" wrote:
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mike" wrote:
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?
Apr 30 '07 #3

P: n/a
I suppose another simple one would be to Response.Redirect to the page,
however, anything done in viewstate would then be lost. This would be fine
if you were just saving data to a database or something like.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:9E**********************************@microsof t.com...
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mike" wrote:
>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?

Apr 30 '07 #4

P: n/a
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_20...ge-refresh.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
May 31 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.