<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function CheckList1_Validator(sender, args) {
args.IsValid = false; //Default the validation return value to false
var cnt = $('#<%=CheckBoxList1.ClientID %> input:checked').length;
args.IsValid = (cnt >= 3); //Return the validation result by checking if at least three items have been selected
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Connecticut" Value="CT"></asp:ListItem>
<asp:ListItem Text="Massachusetts" Value="MA"></asp:ListItem>
<asp:ListItem Text="New York" Value="NY"></asp:ListItem>
<asp:ListItem Text="New Hampshire" Value="NH"></asp:ListItem>
<asp:ListItem Text="Rhode Island" Value="RI"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<p></p>
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ForeColor="Red" ErrorMessage="Please select at least 3 states"
ClientValidationFunction="CheckList1_Validator"></asp:CustomValidator>
</div>
</form>
</body>
</html>
<head runat="server">
<title></title>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function CheckList1_Validator(sender, args) {
args.IsValid = false; //Default the validation return value to false
var cnt = $('#<%=CheckBoxList1.ClientID %> input:checked').length;
args.IsValid = (cnt >= 3); //Return the validation result by checking if at least three items have been selected
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="Connecticut" Value="CT"></asp:ListItem>
<asp:ListItem Text="Massachusetts" Value="MA"></asp:ListItem>
<asp:ListItem Text="New York" Value="NY"></asp:ListItem>
<asp:ListItem Text="New Hampshire" Value="NH"></asp:ListItem>
<asp:ListItem Text="Rhode Island" Value="RI"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<p></p>
<asp:CustomValidator ID="CustomValidator1" runat="server" Display="Dynamic" ForeColor="Red" ErrorMessage="Please select at least 3 states"
ClientValidationFunction="CheckList1_Validator"></asp:CustomValidator>
</div>
</form>
</body>
</html>