0

Possible Duplicate:
Post-Redirect-Get with ASP.NET

I have a button on my form. Inside the button_click event I insert some data to database. If I click that button and then refresh the page, it seems the button gets clicked again because I find the same data inserted to the database twice. Is there a way to prevent this?

Community
  • 1
  • 1
Mikayil Abdullayev
  • 12,117
  • 26
  • 122
  • 206
  • Please post some relevant code – Blachshma Dec 22 '12 at 13:44
  • Also this is similar q/a: http://stackoverflow.com/questions/6615403/detect-browser-refresh – Aristos Dec 22 '12 at 13:51
  • @Aristos, I understand that this is a possible duplicate. But I have to first know what Post-Redirect-Get is to ask a question containing it. Neither of the posts you referred to have a question similar to mine. That's why I asked this question. – Mikayil Abdullayev Dec 22 '12 at 13:54
  • @MikeJM I am not say anything against you at all (nether vote anything minus), and I understand that you can not locate it, I just give some links try to help you to see possible solutions. – Aristos Dec 22 '12 at 13:55

2 Answers2

2

You have to use PRG patern to avoid this problem. When you refresh the page your last request(either get or Post) resubmitted to the server again.

Solution: In the click event use this at the last

  Response.Redirect(@"~\page.aspx");
syed mohsin
  • 2,948
  • 2
  • 23
  • 47
1

after insert you can redirect to the same page using Response.Redirect(Request.RawUrl)

this will prevent the problem

Mahmoud Farahat
  • 5,364
  • 4
  • 43
  • 59
  • What you have type here is work, but the user did not understand nether know if the data is final insert by just reload the page. – Aristos Dec 22 '12 at 13:47