Required Validator on CheckBoxList

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Can you use a Required Validator on a CheckBoxList?

You can on a RadioButtonList.

But when I try on my CheckBoxList I get the error:

Control 'RFPServiceTypes' referenced by the ControlToValidate property of
'ServiceTypesCheck' cannot be validated

<asp:CheckBoxList id="RFPServiceTypes" CellPadding="0" CellSpacing="0"
runat="server"/>
<asp:RequiredFieldValidator id="ServiceTypesCheck"
ControlToValidate="RFPServiceTypes"
text = "You Must Choose At Least One Service Type"
runat="server"/>

I just want to make sure that one of the checkboxes are checked.

Thanks,

Tom
 
tshad said:
Can you use a Required Validator on a CheckBoxList?

You can on a RadioButtonList.

But when I try on my CheckBoxList I get the error:

Control 'RFPServiceTypes' referenced by the ControlToValidate property of
'ServiceTypesCheck' cannot be validated

<asp:CheckBoxList id="RFPServiceTypes" CellPadding="0" CellSpacing="0"
runat="server"/>
<asp:RequiredFieldValidator id="ServiceTypesCheck"
ControlToValidate="RFPServiceTypes"
text = "You Must Choose At Least One Service Type"
runat="server"/>

I just want to make sure that one of the checkboxes are checked.

I found that you apparently can't.

But I found a couple of places that show you how to create a custom
validator that does the trick.

Tom
 
Tom,

If you want a validator that acts on the checkboxlist exactly the same way
as the built in validator works on a radio button list (and lets you set how
many checkboxes need to be selected) I built one and am giving it away,
including source, on my website, www.aboutfortunate.com. If you'd like to
download it click the "Code Library" button at the top of the page and then
click the "Check Box Required Field Validator" button that will appear in
the menu on the left.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S. Justin Gengo said:
Tom,

If you want a validator that acts on the checkboxlist exactly the same way
as the built in validator works on a radio button list (and lets you set
how many checkboxes need to be selected) I built one and am giving it
away, including source, on my website, www.aboutfortunate.com. If you'd
like to download it click the "Code Library" button at the top of the page
and then click the "Check Box Required Field Validator" button that will
appear in the menu on the left.

I hadn't seen this post, when I responded to your other post.

Thanks for the help.

This will help me get a better handle on the making changes to different
classes. I have another one dealing with radio buttons and Datagrids that I
wanted to make a change to, but hadn't got to it yet.

Thanks,

Tom
 
Back
Top