How can I ensure that the asp button is disabled only after the user submits the form with the correct regular expression?
Below is the form code:
<asp:TextBox ID="TextBox2" runat="server" placeholder="Email" class="form-control" type="email" Font-Size="Large" oninvalid="setCustomValidity(')"></asp:TextBox>
<asp:Button ID="Button1" runat="server" class="btn btn-primary btn-block btn-lg" Text="Submit" OnClick="Button1_Click" ValidationGroup="S" UseSubmitBehavior="false" OnClientClick="myFunction2()" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" ControlToValidate="TextBox2" runat="server" ErrorMessage="Invalid Email" ValidationGroup="S" Visible="false" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
Here is the validation javascript function:
<script>
function myFunction2() {
if (Page_ClientValidate('S')) {
document.getElementById('Button1').disabled = true;
document.getElementById('Button1').value = "Please waitً";
}
}
</script>
The issue is that the button gets disabled even when the text box value does not pass the email regex check.
Code Behind:
protected void Button1_Clicked(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}