I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.
I have tried naively disabling the button with java
Just heard about the "DisableOnSubmit" property of an
When rendered, the button's onclick attribute looks like so:
onclick="this.disabled=true; setTimeout('enableBack()', 3000);
WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions('yourControlsName', '', true, '', '', false, true))
And the "enableBack()' javascript function looks like this:
function enableBack()
{
document.getElementById('yourControlsName').disabled=false;
}
So when the button is clicked, it becomes disabled for 3 seconds. If the form posts successfully then you never see the button re-enable. If, however, any validators fail then the button becomes enabled again after 3 seconds.
All this just by setting an attribute on the button--no javascript code needs to be written by hand.