Reputation: 15861
as i am developing a web application in asp.net, There is 4 text boxes to provide user deatils and a button to save the information in DB. When User click the button to Insert the user deatil, it is saved in DB perfectly, but the problem is when the user Refreshes the page, that data is again re inserted / resubmitted, i want to make sure that duplicate submission should be avoided .
Please any suggestion, code samples, to avoid this situation are welcome ( in c#)
Upvotes: 0
Views: 1417
Reputation: 9680
Put a field in page call it status for example, after submitting first time it's populated with SUCCESS. If it is the do not save again.
Not the ultimate solution for sure.
Upvotes: -1
Reputation: 691655
Use the Post-Redirect-Get (also known as Redirect after post) pattern. It simply consists in redirecting after a successful post, so that the user refresh results in an idempotent GET to be done rather than a POST. It has the additional advantage that the browser "forgets" about the POST in its history, which means the back button won't submit either.
Upvotes: 2