Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

JavaScript disable button

How would I go about disabling a .Net button on Click event using JavaScript?
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Russ Suter
Russ Suter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<asp:Button ID="Button1" runat="server" Text="Button"  onclientclick="disableBtn"/>

<script type="text/javascript">
    function disableBtn()
    {
    var btn= document.getElementById("<%=Button1.ClientID%>");
    btn.disabled=true;
    }
</script>



get the button id

Var button1=document.getElementById('<%= btnName.ClientID %>')
button1.style.display="block";

or

document.getElementById("button1").style.display="block";

or disable like this

btnName.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(btnName).ToString());

incase of restricting multiple click on postback

http://encosia.com/disable-a-button-control-during-postback/
Avatar of Larry Brister

ASKER

You guys were first.
Thanks