How to avoid the button events on Refresh of page?

When the user clicks F5 (or uses a toolbar button to refresh the page) it will cause a new request, identical to the previous one, to be sent to the server. The Button. Click event will be raised again, but you have a few ways to protect yourself against inserting the data twice.

When the user clicks F5 (or uses a toolbar button to refresh the page) it will cause a new request, identical to the previous one, to be sent to the server. The Button. Click event will be raised again, but you have a few ways to protect yourself against inserting the data twice.

The best way, IMHO, is to use the Post/Redirect/Get pattern. In your code, right after the point where the data is saved, do a 302 redirect to a confirmation page: protected void btnSaveStuff_Click(object sender, EventArgs e) { SaveStuffToDatabase(); Response. Redirect("confirmation.

Aspx"); } When using the pattern, the POST to the original page will not end up in the browser history, and refreshing the result page will cause the final GET to be repeated, which should be safe.

I read the article. But How to use GET/POST in master detail scenario then? – Red Swan Feb 1 '10 at 5:22 I am not sure what you mean by "master detail scenario".

As shown in my code sample, you simply need to do a Response. Redirect, which will "cancel" then POST and make the browser to a fresh GET. – Jørn Schou-Rode Feb 1 '10 at 8:18 ok i'll try this, thankx for reply – Red Swan Feb 3 '10 at 5:20.

The refresh will re-submit the form you posted last time when you clicked the button. Usually, when you refresh a page you think of GETing the page again, or doing an HTTP GET, but since the last thing you did was a POST (when you clicked the submit button) the browser will perform the post again to attempt to invoke the same response. I suggest using the Post/Redirect/Get pattern as suggested by Jorn Schou-Rode.

This article also seems relevant. aspalliance.com/687_Preventing_Duplicate....

I don't think TJB the second link that you provided is use full. I needs too much execution right? Really code is good but not proper way.

See If I have 100 pages so according to this article I need to code on each page with respective fields. Which is wrong. Is any other way?

Please – Red Swan Feb 10 '10 at 5:17.

Found this post in a search. Just adding another solution for this problem. Add this in your class: #region Browser Refresh private bool refreshState; private bool isRefresh; protected override void LoadViewState(object savedState) { object AllStates = (object)savedState; base.

LoadViewState(AllStates0); refreshState = bool. Parse(AllStates1.ToString()); if (Session"ISREFRESH"! = null && Session"ISREFRESH"!

= "") isRefresh = (refreshState == (bool)Session"ISREFRESH"); } protected override object SaveViewState() { Session"ISREFRESH" = refreshState; object AllStates = new object3; AllStates0 = base.SaveViewState(); AllStates1 =!(refreshState); return AllStates; } #endregion And in your button click do this: protected void Button1_Click(object sender, EventArgs e) { if (isRefresh == false) { Insert Code here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions