I want to allow only one checkbox to be checked .
Use a RadioButton Class instead.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have a panel with checkboxes:
<asp:Panel runat="server" ID="pnlMyPanel" GroupingText="My Panel Test" Visible="false">
<div class="DetailsBoxSetting">
<asp:CheckBox ID="chk_One" runat="server" CssClass="chk" />
<asp:Label ID="lbl_one" CssClass="StandardLabel" runat="server">One</asp:Label>
</div>
<div class="DetailsBoxSetting">
<asp:CheckBox ID="chk_Two" runat="server" CssClass="chk" />
<asp:Label ID="lbl_Two" CssClass="StandardLabel" runat="server">Two</asp:Label>
</div>
</asp:Panel>
I want to allow only one checkbox to be checked .
How do I do that ?
Thank you
I want to allow only one checkbox to be checked .
Use a RadioButton Class instead.
Hi @Bill Johnson ,
I think you can use javascript
to allow only one checkbox to be checked.
onclick="javascript:UnCheckOtherCheckBox(this, 'chk_Two');"
in chk_One
.
onclick="javascript:UnCheckOtherCheckBox(this, 'chk_One');"
in chk_Two
.
<script type="text/javascript">
function UnCheckOtherCheckBox(chkbox1, chkbox2) {
if (chkbox1.checked) {
//Uncheck the other checkbox
document.getElementById(chkbox2).checked = false;
}
}
</script>
<asp:Panel runat="server" ID="pnlMyPanel" GroupingText="My Panel Test">
<div class="DetailsBoxSetting">
<asp:CheckBox ID="chk_One" runat="server" CssClass="chk" onclick="javascript:UnCheckOtherCheckBox(this, 'chk_Two');" />
<asp:Label ID="lbl_one" CssClass="StandardLabel" runat="server">One</asp:Label>
</div>
<div class="DetailsBoxSetting">
<asp:CheckBox ID="chk_Two" runat="server" CssClass="chk" onclick="javascript:UnCheckOtherCheckBox(this, 'chk_One');" />
<asp:Label ID="lbl_Two" CssClass="StandardLabel" runat="server">Two</asp:Label>
</div>
</asp:Panel>
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.