Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Saturday, September 02, 2006

Disable a button onclick in ASP.NET

//Code behind
protected void Page_Load(object sender, EventArgs e)
    myButton.Attributes.Add("onclick", "this.disabled=true;document.forms[0];");

//In the form you have two buttons, one visible and one hidden
//The visible button is the one you disable with javascript
//and the hidden button is the one you actually click with javascript
//causing the server side event to fire
<asp:button id="myButton"

<asp:button id="myRealButton"
style="DISPLAY: none"

Post a Comment

Anonymous said...

Good one..
there is also another way to do this