In this article I will explain how to validate ASP.Net CheckBoxList control using Custom Validator and perform at least one CheckBox Checked Validation in it. The ASP.Net Custom Validator will make us eof JavaScript function to validate the CheckBoxList control
If you need to learn about how to use JavaScript to validate CheckBoxList control, please refer my article
 
HTML Markup
The HTML Markup consists of an ASP.Net CheckBoxList control, a Custom Validator and a Button. For the Custom Validator I have set the ClientValidationFunction property using which it will call the JavaScript function ValidateCheckBoxList discussed later.
Select Fruits<br />
<asp:CheckBoxList ID="chkFruits" runat="server">
    <asp:ListItem Text="Mango" />
    <asp:ListItem Text="Apple" />
    <asp:ListItem Text="Banana" />
    <asp:ListItem Text="Pineapple" />
    <asp:ListItem Text="Guava" />
    <asp:ListItem Text="Grapes" />
    <asp:ListItem Text="Papaya" />
</asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" ErrorMessage="Please select at least one item."
    ForeColor="Red" ClientValidationFunction="ValidateCheckBoxList" runat="server" />
<br />
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" /><br />
 
 
CustomValidator ClientValidationFunction
Below is the JavaScript function that gets executed when the Custom Validator is trigged on the button click. It first gets the CheckBoxList and its internal CheckBoxes and then a loop is executed to check whether the CheckBoxes are checked or unchecked.
If a CheckBox is found checked then the IsValid variable is set to true else false.
<script type="text/javascript">
    function ValidateCheckBoxList(sender, args) {
        var checkBoxList = document.getElementById("<%=chkFruits.ClientID %>");
        var checkboxes = checkBoxList.getElementsByTagName("input");
        var isValid = false;
        for (var i = 0; i < checkboxes.length; i++) {
            if (checkboxes[i].checked) {
                isValid = true;
                break;
            }
        }
        args.IsValid = isValid;
    }
</script>
 
Validate ASP.Net CheckBoxList (at least one CheckBox checked) using Custom Validator
 
Demo
 
Downloads