Overriding OnClientClick causing validation to fire multiple times

267 Views Asked by At

I'm trying to prevent a form from being submitted multiple time. It uses a validation summary so I am overriding the OnClientClick event for the submit button. It works as expected, the window showing the list of errors is being loaded multiple times.

<asp:Button ID="btnSubmit" runat="server" 
            Text="Submit" 
            CausesValidation="False" 
            ValidationGroup="vgApplication" 
            OnClientClick=" if ( Page_ClientValidate() ) { this.value='Submitting..'; this.disabled=true; }" 
  />
1

There are 1 best solutions below

1
Antarr Byrd On BEST ANSWER

The problem was that I have multiple ValidationGroups on my form. So I had to specify which ValdationGroup to run by passing in the name to Page_ClientValidate().

<asp:Button ID="btnSubmit" runat="server" 
            Text="Submit" 
            CausesValidation="False" 
            OnClientClick=" if ( Page_ClientValidate('vgApplication') ) { this.value='Submitting..'; this.disabled=true; }" 
  />