ericpap
ericpap

Reputation: 2937

How to disable button on submit and enabled on ASP.NET postback complete

I'm trying to disable two ASP.NET buttons on submit, and re-enabled them on postback complete. To disable the buttons I use this code:

cmdFiltrar.Attributes.Add("onclick", "javascript:" + cmdFiltrar.ClientID + ".disabled=true;" + ClientScript.GetPostBackEventReference(cmdFiltrar, ""))
cmdExcel.Attributes.Add("onclick", "javascript:" + cmdExcel.ClientID + ".disabled=true;" + ClientScript.GetPostBackEventReference(cmdExcel, ""))

And it Works. But how or in wich event can i re-enabled them? I already try on page load event, but it seems not a any have effects.

Any ideas? thanks!

Upvotes: 0

Views: 1818

Answers (1)

Sam
Sam

Reputation: 2917

You are not using Ajax to do a post back. You are just enabling client side scripts (JavaScript) to cause a full post back to the server (raise an event using __doPostBack) unless there's an UpdatePanel involved. If there's an UpdatePanel it'll do a partial postback. Anyway, here's a solution for both cases.

Add this JavaScript to your page.

<script type="text/javascript">
 function EnableButton() {

  var btn = document.getElementById("<%= cmdFiltrar.ClientID %>");
     if (btn.disabled == true) {
       btn.disabled = false;
    }
 }
</script> 

If there's a full postback

Call the above JavaScript in your body onLoad event

<body onload="EnableButton();">

If there's a partial postback

Call the JavaScript function in your UpdatePanel's client side onLoad event

Upvotes: 2

Related Questions