I'm relatively new at web & ASP.Net development, so bear with me. In the course of testing our web pages, I noticed that if a user were to click "Refresh/Reload", and clicks "Retry" when prompted on the "Resend Info" dialog box, whatever last event that was fired before the user chose to "Refresh", will subsequently be fired again.
As an example we have "Previous" and "Next" Nav buttons which allows a user to navigate through a series of questions. Should the operator hit "Refresh/Reload", which ever Nav button the user pressed last will fire again. This actually makes some sense, but the net effect is the user ends up on the next or previous page from which he was formerly viewing. Is there a work around for this sort of thing?
views:
366answers:
2This is due to the way you are handling PostBacks.
A little background is necessary:
The web is "stateless", which means each request from a client to a server is independent of the request before it or the request after it. There is no "state" maintained. If you look at the HTTP level, it's simply a text blob sent to the server that says "send me this information" and the server sends it back. There's no "I am the same user who was here 3 minutes ago and I would like to move to the next page from the one I was on last time we spoke".
The way ASP.NET solves this problem is using ViewState and postbacks. Every time you click an ASP.NET button, it is actually submitting a form which has a hidden field with a bunch of encoded data. That data contains all of the information the server needs to "reconstruct" the state of the page as it was the last time it. Then it can execute the "move to next page" and that command makes sense. When ASP.NET sends the HTML back to the client, it updates that hidden field with new data, again representing the state of the page, as it is right now. And the next time you click any button, the data is sent again, the page is reconstructed again and the cycle repeats.
When the user hits "refresh" the browser asks them if they want to re-submit the form. They are resubmitting the same data they did last time round.
Implications for you:
If you attempt to track any data about the user or what they are doing independently of the ASP.NET ViewState, you will need to make sure you synchronize that each time the page processes.
You probably want to keep the "current page" in ViewState:
ViewState.Add("CurrentPage", intCurrentPage);
So when you call the MoveNext
event handler, you can be sure you are moving relative to the page as it was the last time it was sent to the client.
You could look towards the Post-Redirect-Get pattern that is more commonly used in asp.net mvc.
See here for more details.