Required field validator for CheckBoxList

<asp:CheckBoxList ID="chkDepartments" runat="server" RepeatDirection="Horizontal"></asp:CheckBoxList>
                <asp:CustomValidator runat="server" ID="chkT"
                    ClientValidationFunction="ValidateDepartments"

                    ErrorMessage="Please select atleast one Department" ValidationGroup="k" ForeColor="Red"></asp:CustomValidator>


<script type="text/javascript">
        function ValidateDepartments(source, args) {
            var chkListModules = document.getElementById('<%= chkDepartments.ClientID %>');
            var chkListinputs = chkListModules.getElementsByTagName("input");
            for (var i = 0; i < chkListinputs.length; i++) {
                if (chkListinputs[i].checked) {
                    args.IsValid = true;
                    return;
                }
            }
            args.IsValid = false;
        }


    </script>

Hope this will helps you................

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell