How is this done?

  • Thread starter Thread starter Brian W
  • Start date Start date
B

Brian W

I'm sure this has been covered before, but I'll be damned if I can find it.

So if someone could point me in the right direction I'll be grateful.

I have a contact page, where the user enters their email address some other
data, a message, etc, then they click "Send" my page then gathers all the
data and uses SmtpMail to email it to an email address I have set up. (No,
at this time I don't want to setup SQL server)

When the email is successfully sent the asp:Panel that holds the control for
the email is hidden and an asp:Panel is made visible indicating success.

This is all working great!, except...

If the user presses refresh while the success panel is displayed the email
is sent again. Also, if the user navigates away from the page then uses the
back button to get to the success message the pages is expired (that's the
way I wrote it) and presses refresh to resubmit the data, again, the email
is sent.

I'm sure I'm missing something obvious, but how do I prevent this behavior?


TIA
Brian W
 
Hi Brian,

When the user click refresh button, the form in the web page will be submit
again. To prevent this, you may add following code after you send email on
server side:

Session("SentCompleted") = 1
Response.Redirect("WebForm1.aspx")

"WebForm1.aspx" is just the web form we are working with. To redirect to
itself, the form data will be clear so that it won't be submited again when
click refresh button.

In the form_load, we can set the control's property according the session
variant "SentCompleted":

If Session("SentCompleted") = 1 then

...

End If

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top