469,943 Members | 2,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

Refersh problem

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

Nov 18 '05 #1
6 1187
bhavik <bh****@discussions.microsoft.com> typed:
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.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #2
hi

U gave the reason behind it but I need a solution.
what should i do??
bhavik

"Davide Vernole [MVP]" wrote:
bhavik <bh****@discussions.microsoft.com> typed:
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.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Nov 18 '05 #3
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.No Cache)
Response.Expires = -1

"bhavik" wrote:
hi

U gave the reason behind it but I need a solution.
what should i do??
bhavik

"Davide Vernole [MVP]" wrote:
bhavik <bh****@discussions.microsoft.com> typed:
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.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Nov 18 '05 #4
hi Lenn

I have try it but it's not working. plz help me out this problem.

"Lenn" wrote:
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.No Cache)
Response.Expires = -1

"bhavik" wrote:
hi

U gave the reason behind it but I need a solution.
what should i do??
bhavik

"Davide Vernole [MVP]" wrote:
bhavik <bh****@discussions.microsoft.com> typed:
> 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.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer

Nov 18 '05 #5
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

"bhavik" wrote:
hi Lenn

I have try it but it's not working. plz help me out this problem.

"Lenn" wrote:
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.No Cache)
Response.Expires = -1

"bhavik" wrote:
hi

U gave the reason behind it but I need a solution.
what should i do??
bhavik

"Davide Vernole [MVP]" wrote:

> bhavik <bh****@discussions.microsoft.com> typed:
> > 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.
>
> --
> Davide Vernole
> MVP ASP/ASP.NET
> Microsoft Certified Solution Developer
>
>
>

Nov 18 '05 #6
You can also try setting the property smartNavigation = true;

What type of button are you using?

"Lenn" wrote:
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

"bhavik" wrote:
hi Lenn

I have try it but it's not working. plz help me out this problem.

"Lenn" wrote:
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.No Cache)
Response.Expires = -1

"bhavik" wrote:

> hi
>
> U gave the reason behind it but I need a solution.
> what should i do??
> bhavik
>
> "Davide Vernole [MVP]" wrote:
>
> > bhavik <bh****@discussions.microsoft.com> typed:
> > > 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.
> >
> > --
> > Davide Vernole
> > MVP ASP/ASP.NET
> > Microsoft Certified Solution Developer
> >
> >
> >

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

117 posts views Thread by Peter Olcott | last post: by
28 posts views Thread by Jon Davis | last post: by
6 posts views Thread by Ammar | last post: by
2 posts views Thread by Mike Collins | last post: by
6 posts views Thread by amit | last post: by
1 post views Thread by ctsasikumar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.