Friday, May 25, 2012

 
Validate Checkboxlist in ASP.NET 
 
 
 function ValidateChkList(source, arguments) {
        arguments.IsValid = IsCheckBoxChecked() ? true : false;
 
    }
 
    function IsCheckBoxChecked() {
        var isChecked = false;
        var list = document.getElementById('<%= chkAuthorAdd.ClientID %>');
        var Checkbox = list.getElementsByTagName("input");
        for (var j = 0; j < Checkbox.length; j++) {
            if (Checkbox[j].checked) {
                isChecked = true;
            }
        }
        return isChecked;
 
    }
 
 
 asp:CheckBoxList ID="chkAuthorAdd" runat="server" CssClass="chkbox" RepeatColumns="2"
                                        RepeatDirection="Horizontal" RepeatLayout="Table" /> 
  <asp:CustomValidator ID="cvAuthor" runat="server" ForeColor="Red"  
ValidationGroup="WhitePaperDetails"  ClientValidationFunction="ValidateChkList">
 Please select Author.</asp:CustomValidator>

No comments:

Post a Comment