/ Published in: C#
Will disable the button and still allow the postback event
Expand |
Embed | Plain Text
btn_Next.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(btn_Next, "").ToString() + ";");
Comments
Subscribe to comments
You need to login to post a comment.

I've been using this version since .NET 2.0 added "OnClientClick":
/included js file/ function disable(btn) { btn.value = "Wait..."; setTimeout(function() { btn.disabled = true; }, 10); }
/.aspx file/
Just include the js in your master page and then every button can easily use it. Also, no more extra code on Page_Load.
Let's try the code again:
/included js file/
function disable(btn) { btn.value = "Wait..."; setTimeout(function() { btn.disabled = true; }, 10); }
/.aspx file/
<asp:Button ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="disable(this);" />