Disable Submit button after it was clicked.

Simple one line code to disable and change the text of the button that goes triggered after submit behavior.

While submitting the form data to a server to be handled by the Click event of Submit button, it would be a good practice to disable the button.  Below is a small code sample to achieve this:

Note: don't apply the technique to the buttons which cause validation. Such buttons require more advanced onclick handler which checks client-side validation result.

Source code

		btnSubmit.OnClientClick = ClientScript.GetPostBackEventReference(btnSubmit, "") + "; this.value='Submitting...';this.disabled = true;";
 
blog comments powered by Disqus