Click here to Skip to main content
15,887,272 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
My application working well. but when i click browser Refersh(F5) button postback happens. How do i avoid this postback in asp.net.

Thanks,
Mangesh B.
Posted

This is how the web works. If your last action was a POST, F5 repeats it. The way around it is for every postback to set up the state needed for your page to render itself ( so nothing lives in viewstate ) and doing a response.Redirect back to your page. This turns the POST into a GET, and F5 will do a GET, and render the page, which will render in the state you requested, because of values on the URL and in the session
 
Share this answer
 
Comments
Member 8090436 5-Aug-12 2:10am    
Thanks for quick reply. But what i do for avoid this ?
Christian Graus 5-Aug-12 2:12am    
You do exactly what I told you to. Someone else has posted some articles, if you could not understand my answer, you probably need something more in depth and at your level, so I suggest reading those.
This is due to how browsers work. Preseeing Refresh just repeats the last request. Example: The first time you POST the page, the browser sends all the data, then returns back HTML to render. If you hit refresh (F5) then the browser re-sends the last POST request thus re-sending the information again. You cannot avoid the postback but can find and handle it if you want to.

See few tips here:
Refresh Page Issue in ASP.Net[^]
Stop Refresh after Submitting your Request[^]
Detecting Page Refresh[^]
 
Share this answer
 
Comments
Pankaj Nikam 5-Aug-12 5:37am    
+5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900