CodeKicks.com
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].myRealButton.click();");
}

//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"
Runat="server"></asp:button>

<asp:button id="myRealButton"
style="DISPLAY: none"
onclick="myASPOnClick"
Runat="server"></asp:button>

Post a Comment

Anonymous said...

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

http://gurmeettech.blogspot.com/2008/12/disable-asp-button-on-submit.html