Validator causes improper behavior for double click check
<p>I have following script to <code>prevent a button from submitting twice</code> by double clicking. It works fine.</p>

<p>But the scenario gets clumsy when I added a <code>Required Field validator</code>. If I try to submit with a blank value in textbox, the validator fires. But when I entered value in textbox and try to submit again it does not do a postback.</p>

<p>I understand the reason, in the first button click itself, the variable isActionInProgress is set as 'Yes' irrespective of the validation error.</p>

<p>What is the best way to overcome this challenge?</p>

<p><strong>MARK UP</strong></p>

<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.1.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

    $(document).ready(function () {



        var isActionInProgress = 'No';

        $('.myButton').click(function (e) {

            if (isActionInProgress == 'No') {
                isActionInProgress = 'Yes';
            }
            else {
                e.preventDefault();
                //alert('STOP');
            }

        });


    });

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
    &lt;asp:TextBox ID="txtEmpName" runat="server"&gt;&lt;/asp:TextBox&gt;
    &lt;asp:Button ID="Button1" CssClass="myButton" runat="server" Text="Submit" ValidationGroup="ButtonClick"
        OnClick="Button1_Click" /&gt;

    &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtEmpName"
        runat="server" ErrorMessage="RequiredFieldValidator" ValidationGroup="ButtonClick" Text="*"&gt;&lt;/asp:RequiredFieldValidator&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p></p>

<p>REFERENCES</p>

<ol>
<li><a href="http://stackoverflow.com/questions/969465/problem-with-page-clientvalidate">Problem with Page_ClientValidate</a></li>
<li><a href="http://stackoverflow.com/questions/13565718/hide-redundant-error-message-in-asp-net-validationsummary">Hide redundant error message in ASP.Net ValidationSummary</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa479045.aspx" rel="nofollow">MSDN - ASP.NET Validation in Depth</a></li>
</ol>
