disable submit button on Asp.net using Javascript when user clicks it

 

How to disable Submit  button in Asp.net.  Following script will disable the submit button when you click on it so user can not click it again and again.

Register following javascript on page load event on which your submit button is. btnSave.ClientID is the button you want to disable when user clicks on it. Text on button will be change to “Please wait..”

  

// Define the name and type of the client script on the page.
String csname = “OnSubmitScript”;
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the OnSubmit statement is already registered.
if (!cs.IsOnSubmitStatementRegistered(cstype, csname))
{
String cstext = “if (typeof(ValidatorOnSubmit) == ‘function’ && ValidatorOnSubmit() == false)return false; else { var myCtl = document.getElementById(‘” + this.btnSave.ClientID + “‘); myCtl.value = ‘Please wait…’; myCtl.disabled = true;}”;
cs.RegisterOnSubmitStatement(cstype, csname, cstext);
}


Tags: , , , , ,

Comments are closed.