Wednesday, October 29, 2008

What's the difference between refresh and postback?

1) typing in a url is like going to the page for the first time so its not a postback. If you browser has cached the page, you may actually go nowhere.

2) clicking on an asp:button fires a javascript that submits your form and is detected at the server as a postback for the page.

3) hitting a browser refresh (F5) takes whatever post data is currently in the buffer (from the last time the page form was submitted) and resubmits it. It does not submit current form values.

Item 3 is usually the most problematic to deal with.

If you refresh the page and it has never been posted back, then its like you are hitting it for the first time on each refresh.

If, however, the page had already been posted back, then hitting refresh repeats whatever event cause it to be previously posted back. This repeated event may not be an issue, but there are defineated times when it would be disastrous to repeat a postback event.

There are mechanisms around to detect when a page that has already been posted back is being refreshed.


No comments: