Checkbox To Control Button Enabled Property - Asp.net
I would like to know how I can control the 'Enabled' property of a button based on the 'checked' value of a checkbox: <
Solution 1:
Javascript:
<scripttype="text/javascript">functioncheckButt(obj) {
document.getElementById('<%=btnLoadForm.ClientID%>').disabled = !obj.checked;
}
</script>
Web Controls:
<asp:CheckBoxID="chkEnableButton"runat="server"OnClientClick="checkButt(this);" /><asp:ButtonID="btnLoadForm"runat="server" />
Solution 2:
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.
Solution 3:
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()" />
Post a Comment for "Checkbox To Control Button Enabled Property - Asp.net"