Code is reexecuted when the user clicks Refresh

N

Nathan Sokalski

I have a page which allows the user to send emails. After they click the
submit button, I display a confirmation message. However, if the user clicks
the browser's Refresh button once the confirmation message is displayed, the
email is sent a second time (or a third, fourth, fifth, etc.). What can I do
to prevent the Refresh button from resending the email? Thanks.
 
R

RSH

Nathan,

You could set a session varaible that once the email was sent the session
variable would be sent and you would add a wrapper to check for a value in
the session variable before sending emails.

If they hit the refresh button does that cause a postback...I'm not sure.
If not, then you can simply check if the request is a postback...if it is
send the email...else dont.

HTH
Ron
 
K

Keith Patrick

Maybe Response.Redirect? That will flush out your POST headers to prevent
the submit from happening repeatedly
 
O

\(O\)enone

Keith said:
Maybe Response.Redirect? That will flush out your POST headers to
prevent the submit from happening repeatedly

This is the approach we use. It works perfectly.
 
C

Cor Ligthert [MVP]

Nathan,

You can try to set a session variable that tells that the post has been
send.

Cor
 
G

Guest

I have a page which allows the user to send emails. After they click
the submit button, I display a confirmation message. However, if the
user clicks the browser's Refresh button once the confirmation message
is displayed, the email is sent a second time (or a third, fourth,
fifth, etc.). What can I do to prevent the Refresh button from
resending the email? Thanks.

Session variables, database flag, cookies - since the web is stateless,
you'll need some sort of mechanism to track when the last request occured
and if the current request is valid.
 

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,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top