Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to detect browser Refresh ?
Posted

1 solution

You have not shared on why you want to detect it, but generally this is asked to avoid re-submit data because of Page refresh.

This is due to how browsers work. 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. This causes duplication of record. One need to apply Post-Redirect-Get pattern for such scenarios/pages, where after an HTTP Post, instead of returning HTML, is redirected back to a page (either the same or another).

In case, you cannot redirect or not comfortable with redirect, have a look at these articles:
Refresh Page Issue in ASP.Net[^]
Stop Refresh after Submitting your Request[^]
Detecting Page Refresh[^]
 
Share this answer
 

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