Checkbox to Control Button Enabled Property - ASP.NET

后端 未结 3 706
深忆病人
深忆病人 2021-01-28 17:06

I would like to know how I can control the \'Enabled\' property of a button based on the \'checked\' value of a checkbox:



        
相关标签:
3条回答
  • 2021-01-28 17:36

    Javascript:

    <script type="text/javascript">
    function checkButt(obj) {
        document.getElementById('<%=btnLoadForm.ClientID%>').disabled = !obj.checked;
    }
    </script>
    

    Web Controls:

    <asp:CheckBox ID="chkEnableButton" runat="server" OnClientClick="checkButt(this);" />
    <asp:Button ID="btnLoadForm" runat="server" />
    
    0 讨论(0)
  • 2021-01-28 17:43

    This SO question might give you a hint of how to do this. In your situation however, instead of changing the text of the Checkbox, find the Button control on your page and change it's disabled property.

    0 讨论(0)
  • 2021-01-28 17:51

    You can use here ClientID attribute so you can get the control on client side via javascript using document.getElementById or document.forms[0].elements[clientID].

    function enableButton() {
    
    $get('<%= btnLoadForm.ClientID %>').disabled = !$get('<%= chkEnableButton.ClientID %>').checked;
    
    }
    
    <asp:CheckBox ID="chkEnableButton" runat="server" OnClientClick="enableButton()" />
    
    0 讨论(0)
提交回复
热议问题