Code is reexecuted when the user clicks Refresh

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
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.
 
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
 
Maybe Response.Redirect? That will flush out your POST headers to prevent
the submit from happening repeatedly
 
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.
 
Nathan,

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

Cor
 
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.
 
Back
Top