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

            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 = ""


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

        End Try


Who is Participating?
RomModConnect With a Mentor Commented:
Question closed - 125 points refunded.

Best regards,
Experts Exchange
Community Support Moderator
ainaks25Author Commented:
I found the solution:

<SCRIPT language=JavaScript > 

var submitcount=0;

function checkSubmit()

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




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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.