473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

ASP.NET Postback Event Occurrs Again after page refresh

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
4 6704
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt | last post by:
I always see the term "postback" from ASP book, but I am not sure if I fully understand the meaning. Here's my understanding so far, please correct me if any mistakes. Here's a typical html...
7
by: Michel | last post by:
Hi all, Is there some intelligent way to trigger a clientside JavaScript function before a postback is triggerd by any of the controls on a page? Thanks in advance, Michel Mathijssen
1
by: Rhys | last post by:
I have a page which has an IFrame on it. The src of the IFrame is a page with a datagrid on it. The Datagrid has bound template columns. The columns of the datagrid pass the bound data value of...
2
by: Earl Teigrob | last post by:
I have run into a situation where I need to run the !IsPostBack code under one circumstance, even if it is a postback. Something that may complicate matters more is that this is a double postback...
10
by: tasmisr | last post by:
This is an old problem,, but I never had it so bad like this before,, the events are refiring when clicking the Browser refresh button. In the Submit button in my webform, I capture the server side...
7
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but...
11
by: antonyliu2002 | last post by:
I know that this has been asked and answered thousands of times. As a matter of fact, I know that I need to say If Not Page.IsPostBack Then 'Do something End If for things that needs to be...
4
by: Dan | last post by:
Hi, i'm not sure to understand the difference between refreshing the pagina by clicking on 'refresh' in the browser and a postback. What i think it is: Suppose a page with a form containing a...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.