Refresh button

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
 
A

Aidy

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

Guest

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
 
A

Anthony Jones

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
 
S

SimonZ

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
 
R

rote

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top