Refersh problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi
i have one aspx page on which i have one button

in code behind i wrote a code for inserting a record.
if i clicik on button it inserts a record
ok ite fine
but the problem is that if i refresh the page
it will go again into button_click event and add the same record again

why so. ?

plz help me
 
bhavik said:
hi
i have one aspx page on which i have one button

in code behind i wrote a code for inserting a record.
if i clicik on button it inserts a record
ok ite fine
but the problem is that if i refresh the page
it will go again into button_click event and add the same record again

why so. ?

plz help me

Because when you require a refresh from your browser, it perfome the last
request you made. In your case this request contains the postback event
generate clicking the button.
 
Yes, the problem is that the browser caches the last request info. Refresh
causes resubmission of the last request. You want to prevent any caching by
the browser. Add this code to page load event:

Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Expires = -1
 
ok keep that code and also add this tag to the <head></head> tag of your page
<HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
What browser are you using? from what you described, I think it is a problem
with page last request being cached and resubmitted on refresh...
If nothing else works maybe you should build in more logic to check if
record was already insereted by that user. Like store session ID in that
table, and enable unique constraint on that field. THough if you can prevent
user browser from caching it should work (I think)
Good Luck
 
You can also try setting the property smartNavigation = true;

What type of button are you using?
 
Back
Top