Refresh button

  • Thread starter Thread starter SimonZ
  • Start date Start date
S

SimonZ

When user insert some data on page and click save button this data is
inserted to database.

If he clicks refresh button, the data is saved again each time when he
clicks this button.

I would like to prevent refresh from that page, so I inserted the following
lines in code behind on page_load event:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

HtmlMeta metaTag= new HtmlMeta();
metaTag.HttpEquiv = "Pragma";
metaTag.Content = "no-cache";
Header.Controls.Add(metaTag);

HtmlMeta metaTag1 = new HtmlMeta();
metaTag1.HttpEquiv = "expires";
metaTag1.Content = "0";
Header.Controls.Add(metaTag1);

But this won't work. Any idea howw to prevent user to insert the same data
twice(or even more times) with refreshing the page?

regards, Simon
 
Either redirect the user to a different page after the insert, or hace the
code check that what you're trying to insert hasn't already been inserted.
 
Either redirect the user to a different page after the insert, or hace the
code check that what you're trying to insert hasn't already been inserted.











- Show quoted text -

you can also redirect to the same page after the insert
 
SimonZ said:
When user insert some data on page and click save button this data is
inserted to database.

If he clicks refresh button, the data is saved again each time when he
clicks this button.

I would like to prevent refresh from that page, so I inserted the following
lines in code behind on page_load event:

Response.Cache.SetCacheability(HttpCacheability.NoCache);

HtmlMeta metaTag= new HtmlMeta();
metaTag.HttpEquiv = "Pragma";
metaTag.Content = "no-cache";
Header.Controls.Add(metaTag);

HtmlMeta metaTag1 = new HtmlMeta();
metaTag1.HttpEquiv = "expires";
metaTag1.Content = "0";
Header.Controls.Add(metaTag1);

But this won't work. Any idea howw to prevent user to insert the same data
twice(or even more times) with refreshing the page?

regards, Simon

Your code is attempting to stop the browser from caching the output of the
page.

Since the result will be generated by a POST from the browser the content
isn't cached anyway. Also the code is merely adding HttpEquiv meta tags
which are utterly pointless when you could actually control those headers
directly using the appropriate objects (see Response.Cache property).

However what you really want is to srop the client from Re-POSTing the data
which causes the update. First off, you can't stop that if the user presses
refresh they typically get a warning that they're about to post data again,
if they say yes then you get another POST.

The trick then is to know that data has already been accepted for the page
and simply to respond as if the update had occured without doing the update.

A ticketing system is best take a look at the heading Trap the Browser
Refresh in this article.

http://msdn2.microsoft.com/en-us/library/ms379557(VS.80).aspx
 
Thank you Anthony for your suggestion.
The following code doesn't work if I have master page.
Each function is called twice and once with session null value.
Any idea?

Regards,
Simon
 
SimonZ,
Go through Terri's article here at:
http://aspalliance.com/687
That should solve your problem.
Patrick

SimonZ said:
Thank you Anthony for your suggestion.
The following code doesn't work if I have master page.
Each function is called twice and once with session null value.
Any idea?

Regards,
Simon
 
Back
Top