How to prevent duplicate insert or other action when user refresh browser.
How to
prevent Browser Refresh
From my live space.This article is about the solution of duplicate action about the Browser Refresh after postback.
Why the browser refresh will cause the old data to post again.
The page refresh or backwards is a sort of browser internal operation without any notification.
The browser caches the latest request it had served, including viewstate, when you refresh the browser,
it will reissues the data.
Solution:
Reference:
http://aspalliance.com/687_Preventing_Duplicate_Record_Insertion_on_Page_Refresh.all#Page4
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/bedrockaspnet.asp
My Solution: since viewstate will be cached old but session not, we can indicate the browser action by this difference.
if the value of viewstate does not equal to the value of session, then it's refresh action
Create a base page class, then all sub-class can inherit the functionality.
in base page class constructor:
Constructor in Page_PreRender method:
Method: Page_PreRender
In SetActionTick() to set the timestamp of this action.
Method: SetActionTick
The property IsRefresh
Property: IsRefresh
So the sub-page class can use this property.
if (IsRefresh == false)
// Insert





}
浙公网安备 33010602011771号