Wednesday, September 7, 2011

How to disable a button (e.g. Submit button) on client side

If you want to disable a button as soon as user click on it (so they don't click multiple times) , you have to do it on client side. Below is how you can do this.


  1. Add the button first



<asp:button causesvalidation="false" id="SubmitButton" onclick="SubmitButton_Click" onclientclick="DisableSubmitButton()" runat="server" text="Submit" usesubmitbehavior="false">


  1. Add this JavaScript function to the page and you set to go.


function DisableSubmitButton(url) {
var button = document.getElementById('&lt;%= SubmitButton.ClientID %&gt;');
button.disabled = true
button.value = 'Submitting...';
__doPostBack('SubmitRadButton', '')
}

No comments:

Post a Comment