Disabling button when performing some operation in ASP.NET
Disabling button when performing some operation in ASP.NET
In ASP.NET Web Application when we submit some button to process information in server side, we can disable the button as long the server performing the operation and enable the same one response is back. Most of the developer use Button Enable and Disable properties to enable and disable the button. But as an good practice we can use Page.ClientScript.GetPostBackEventReference to achieve the same.
Button1.OnClientClick = ClientScript.GetPostBackEventReference(Button1, "") + "; this.value='Processing...';this.disabled = true;";To do a quick test, you can write the below code block
protected void Page_Load(object sender, EventArgs e) { Button1.OnClientClick = ClientScript.GetPostBackEventReference(Button1, "") + "; this.value='Processing...';this.disabled = true;"; } protected void Button1_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(10000); } }
Sagar S Bhanushali
Comments
Post a Comment