<asp:CheckBoxList ID="CheckBoxList1" runat="server" >
<asp:ListItem Text = "One" Value = "1"></asp:ListItem>
<asp:ListItem Text = "Two" Value = "2"></asp:ListItem>
<asp:ListItem Text = "Three" Value = "3"></asp:ListItem>
<asp:ListItem Text = "Four" Value = "4"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="btn" runat="server" OnClientClick="return Validate()" Text="Click" />
<script language="javascript" type="text/javascript">
function Validate() {
var CHK = document.getElementById("<%=CheckBoxList1.ClientID%>");
var checkbox = CHK.getElementsByTagName("input");
var counter = 0;
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked) {
counter++;
}
}
if (counter > 2) {
alert("You can select maximum 2 checkboxes");
return false;
}
else {
return true;
}
//alert(counter);
}
</script>