Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2006, 10:26 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Execute Code Once Only

Hi All,

I have a piece of code which sends an email out to a customer after buying an item online. The problem is, sometimes, the customer receives the mail several times.

Is there a way to make sure the code executes only once?

Thanks.:(

 
Old May 25th, 2006, 08:30 AM
Authorized User
 
Join Date: Jun 2003
Location: Richmond, VA, USA.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

It sounds like to me that sometimes impatient customers are clicking your submit button multiple time which causes multiple emails to be generated. When the final submission is made disable the submit button with java script so they cant hit the button again. Or if you want to carry it out with asp on the page the is submitting the email do something like this.

'Top of the page that has the CDO mail
if request.cookies("error") ="YES" then
   response.redirect "somepage.asp"
end if
response.cookies("error")="YES"

Earl
www.jhdesigninc.com
 
Old May 25th, 2006, 07:02 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Simply do a response.redirect after the mail is sent - perhaps to a thank you your email is sent page

Wind is your friend
Matt
 
Old May 28th, 2006, 09:00 AM
Authorized User
 
Join Date: Jun 2003
Location: Richmond, VA, USA.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

Hey Matt,
If there is alot of processing going on on the page that is sending the email there may be some lag in the redirect and the user will still be able to "mash" the submit button sending multiple requests before the page is processed.

Originally I said set a cookie but looking over some of my older code I see I have used a javaScript solution the majority of the time to fix this issue.

<script language="JavaScript" type="text/JavaScript">
    //some validation

    function validate(form ){
        if ( form.textfield.value=="" ){
            alert("You must enter a value")
            return false;
        }else{
            form['Submit'].disabled=true;
            return true;
        }
    }
</script>

<form name="form1" method="post" action="page.asp" >
  <input type="text" name="textfield">

  <input type="button" name="Submit" value="Submit" onClick="return validate(this.form);this.submit();">

</form>

Earl
www.jhdesigninc.com
 
Old May 28th, 2006, 07:05 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Providing the redirect is placed correctly I do not believe its possible for any more than one email to be sent. Although I do strongly advise client side form validation I would only use a client side solution as a last resort to ensure only one email is sent - I wouldnt rely on cookies.

Wind is your friend
Matt
 
Old May 29th, 2006, 09:31 AM
Authorized User
 
Join Date: Jun 2003
Location: Richmond, VA, USA.
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to erobb Send a message via Yahoo to erobb
Default

Hey Matt,
I can recreate this and have had issues with multiple clients submissions using a redirect. I found that disabling the submit button is most often the way to go. Impatient button mashers send multiple requests to the page.

That being said if you want it absolutely bullet proof then disable the submit button on submission then process your page and do a redirect. If you dont redirect and the client refreshes the page the information is resubmitted with the form values and another email is generated.

Earl
www.jhdesigninc.com




Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to execute before application (excel) quits ksksasi Excel VBA 3 May 7th, 2008 09:45 PM
Resolved! - code behind button won't execute dartcoach Access VBA 1 February 4th, 2008 06:17 PM
Can't execute code from a freed script pRogNewBie Classic ASP Components 0 October 23rd, 2006 10:46 PM
can't execute code from a freed script violetcrystal Javascript 4 April 21st, 2006 05:04 AM
How do I execute a code every X period of time? Master_D PHP How-To 3 June 8th, 2004 10:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.