bigsplash
asked on
How to validate/group a Checkbox along with a CheckboxList in ASP.NET?
My Web form has two choices for the User, and the choices are mutually exclusive. However, Option 2 (being awake), allows for more than one checkbox. How can I utilize a GroupName to these two controls to enforce that Option 1 is not checked if one of the Option 2 listitems is selected?
Option 1: sleep
Option 2: drive and/or sing and/or eat
<tr>
<td><asp:label id="LabelSleep" Runat="server">Option 1:</asp:label></td>
<td><asp:checkbox id="CheckBoxsleep" runat="server" Text="Sleep"</asp:checkbox ></td>
</tr>
<tr>
<td><asp:label id="LabelAwake" Runat="server">Option 2:</asp:label></td>
<td><asp:CheckBoxList id="CheckBoxList1" runat="server" RepeatDirection="Horizonta l">
<asp:ListItem Value="1">Drive</asp:ListI tem>
<asp:ListItem Value="1">Sing</asp:ListIt em>
<asp:ListItem Value="1">Eat</asp:ListIte m>
</asp:CheckBoxList></td>
</tr>
Option 1: sleep
Option 2: drive and/or sing and/or eat
<tr>
<td><asp:label id="LabelSleep" Runat="server">Option 1:</asp:label></td>
<td><asp:checkbox id="CheckBoxsleep" runat="server" Text="Sleep"</asp:checkbox
</tr>
<tr>
<td><asp:label id="LabelAwake" Runat="server">Option 2:</asp:label></td>
<td><asp:CheckBoxList id="CheckBoxList1" runat="server" RepeatDirection="Horizonta
<asp:ListItem Value="1">Drive</asp:ListI
<asp:ListItem Value="1">Sing</asp:ListIt
<asp:ListItem Value="1">Eat</asp:ListIte
</asp:CheckBoxList></td>
</tr>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
'Validate the User's Option choice. Ideally, this should be a client-side custom validator.
If CheckBoxList1.Items(0).Sel
If CheckBoxValidateOnly.Check
Throw New ArgumentException("Both Options are selected. Please select only Option 1 or Option 2 for your Submission.")
End If
Else
If Not CheckBoxValidateOnly.Check
Throw New ArgumentException("No Option selected. Please select either Option 1 or Option 2 for your Submission.")
End If
End If