Tuesday, 12 April 2011

Disable a button with jQuery and still do postback

If you want to disable a button in a web application to stop it being clicked more than once when a long running process starts this is possible with jQuery.

The one pitfall that comes with disabling a submit button on the client side is that it will cancel the browser’s submit, and thus the postback. Setting the UseSubmitBehavior property to false tells .NET to inject the necessary client script to fire the postback anyway, instead of relying on the browser’s form submission behavior.

for example: