Refersh problem

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
 
D

Davide Vernole [MVP]

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.
 
G

Guest

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
 
G

Guest

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
 
G

Guest

You can also try setting the property smartNavigation = true;

What type of button are you using?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top