I could see, myself and many people are having trouble with this two items in ASP.NET… Refresh Button, Back Button… (I see many people went to the exent of asking how to disable these two buttons in the browser..)
Now what are the problems in Implementing two more boolean variables in Page (IsRefresh, IsPostBack)… If those problems can be circumvened and implemented, it would be a great asset to developers…
When you are answering, if you could also include the steps you are taking in your web app in order to avoid reposting (at times in DB) in such scenarios that would be helpful.
Thanks
The problem with implement the two additional boolean properties is, that there really is no (reliable) way to distinguish Back / Refresh triggered requests. When hitting on of these buttons, the browser will either:
You are experiencing case #2. When the second request occurs, the server will recieve the exact same request data as it did with the original request. Thus, ASP.NET (and most other frameworks) will handle the request just like the original was handled. There are several ways to work around this problem:
ViewState) containing a unique value on the page from where postbacks are expected. Then add some data structure to keep a list of “used” values, along with logic to test for duplicates before doing anything critical.POSTrequest never ends up in the browser history.Solution #3 is dead easy, and works in almost every case. Basically, rather then returning the results/confirmation as a reply to the “critical” postback, do a redirect to a new URL: