2

Since ASP.NET's CheckBoxList control does not allow itself to be validated with one of the standard validation controls (i.e., RequiredFieldValidator), I would like to create a UserControl that I can use in my project whenever I need a checkbox list that requires one or more boxes to be checked.

The standard CheckBoxList can be dragged onto a page, and then you can manually add <asp:ListItem> controls if you want. Is there any way I can create a UserControl that lets me manually (in the markup, not programmatically) insert ListItems from my page in a similar manner?

In other words, can I insert a UserControl onto a page, and then from the Designer view of the Page (i.e., not the designer view of the UserControl), can I manually add my ListItems like so:

<uc1:RequiredCheckBoxList>
   <asp:ListItem Text="A" value="B"></asp:ListItem>
   <asp:ListItem Text="X" value="Y"></asp:ListItem>
</uc1:RequiredCheckBoxList>

If a UserControl is not the appropriate choice for the end result I'm looking for, I'm open to other suggestions.

Please note that I am aware of the CustomValidator control (which is how I plan to validate within my UserControl). It's just a pain to write the same basic code each time I need one of these required checkbox lists, which is why I want to create a re-usable control.

1 Answer 1

1

An easier way to solve this problem is to use the standard CheckBoxList, but create a special server validator control specifically for the CheckBoxList. The following article shows you how to go about this - Creating Validator Controls for the CheckBox and CheckBoxList.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.