1

Im implementing Web Form using ASP.NET in c#, I have a page with few TextBox and a Submit Button, the data from TextBox going to insert into Database when Submit Button is pressed, the page will be retain and no redirect is required.

However, there is a issue after the data has been submitted, if F5/refresh the page without click on the Submit Button, the data will insert again and again.

How can I avoid such issue happen after the first submission?

Thank you in advanced.

sams5817
  • 1,037
  • 10
  • 34
  • 49
  • Have you tried putting it inside a `if(!Page.IsPostBack){}` block? – dtsg Jul 25 '12 at 10:56
  • Duplicate http://stackoverflow.com/questions/1263852/prevent-form-redirect-or-refresh-on-submit – yogi Jul 25 '12 at 10:57
  • possible duplicate of [page refresh is firing the event again](http://stackoverflow.com/questions/6014224/page-refresh-is-firing-the-event-again) – Anuraj Jul 25 '12 at 11:00
  • You should always check if a record exists, if so, don't add that record in the database – JohnnBlade Jul 25 '12 at 11:05
  • there is record checking prior insert, but the record checking seem not working after submitted follow by refresh page manually – sams5817 Jul 25 '12 at 11:10
  • Then you should do your check good, and or do a redirect to the same page – JohnnBlade Jul 25 '12 at 11:16

2 Answers2

3

Place Response.Redirect to the same page after save logic done. This happens because browser repeat last request on F5 in you case this is POST request to save. After Response.Redirect last request will be GET and you problem will be solved

vadim
  • 1,698
  • 1
  • 10
  • 19
-1

Unfortunately you can't prevent something like that because the browser excute the same code again after you press refresh so thier is nothing you can do there but you can use response.redirect to the same page again.

Also you can check for duplication in the database so if that record exist don't save it again.

Hope I Helped