Posted By

derekholmes on 12/11/09


Tagged

button postback


Versions (?)

Disable Button on Postback


 / Published in: C#
 

Will disable the button and still allow the postback event

  1. btn_Next.Attributes.Add("onclick", "this.disabled=true;" +
  2. Page.ClientScript.GetPostBackEventReference(btn_Next, "").ToString() + ";");

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: R-Enemy on December 31, 2009

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.

Posted By: R-Enemy on December 31, 2009

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);" />

You need to login to post a comment.