Hidalgo
Hidalgo

Reputation: 941

ASP.NET Disable Submit button only if all controls are validated

I need to disable the submit button, to prevent double posting.

I added the following attributes to the asp:button:

UseSubmitBehaviour="false" 
OnClientClick="this.disabled='true';this.value='Please wait ...'"

This works only if on the first click all controls of the form are valid. But if any one of the asp:RequiredFieldValidor fails, the button is disabled until the page is refreshed.

Upvotes: 1

Views: 1171

Answers (1)

Deepak Arora
Deepak Arora

Reputation: 440

Use the below code:

 OnClientClick="if (Page_ClientValidate()) { this.disabled='true';this.value='Please wait ...'}" 

Explanation

Page_ClientValidate() This method is used for asp.net client side validation. So, if you page in client side validated then only disable your text box.

Upvotes: 3

Related Questions