Link to home
Start Free TrialLog in
Avatar of ainaks25
ainaks25

asked on

prevent multiple form submission

I have a 1 btnSubmit button that sends an email. users do multiple clicks and we receive all emails. How to avoid this? I did a research and tried a few codes but non of them worked.

This is my code for the button:

-------------------------------------------------------

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Try
            Dim objMail As New MailMessage
            objMail.From = "email1"
            objMail.To = "email2"
            objMail.Subject = "Form"
            objMail.BodyFormat = MailFormat.Html
         
            objMail.Body = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
                & "<body>" & vbCrLf _
                 & "</body>" & vbCrLf _
                & "</html>" & vbCrLf

            SmtpMail.SmtpServer = "192.100.00.104"

            SmtpMail.Send(objMail)

        Catch ex As Exception
         
            lblError.Visible = True
            lblError.Text = ex.Message

        End Try

-----------------------------------------------------------------------------------------


thanks,
Avatar of ainaks25
ainaks25

ASKER

I found the solution:

<SCRIPT language=JavaScript > 

var submitcount=0;

function checkSubmit()
{

if (submitcount == 0)
{ submitcount++; return true; }
else
{ alert('This form has already been submitted.' ); return false; }

}

</SCRIPT>       



and

<form id="Form1" name="MainForm" method="post" runat="server" onSubmit=" return checkSubmit();" >


---------------------------
ASKER CERTIFIED SOLUTION
Avatar of RomMod
RomMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial