Wednesday, May 7, 2014

Checkbox count restriction

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApp.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<script src="Scripts/jquery-2.1.0.min.js"></script>

<script>

$(function () {

$("#pp input:checkbox").click(function () {

if ($("#pp :checked").size() > 2) {

alert('message');

this.checked = false;



}

});

});



</script>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:CheckBoxList ID="pp" AutoPostBack="true" runat="server" OnSelectedIndexChanged="pp_SelectedIndexChanged">

<asp:ListItem Text="1" Value="1"></asp:ListItem>

<asp:ListItem Text="1" Value="1"></asp:ListItem>

<asp:ListItem Text="1" Value="1"></asp:ListItem>

<asp:ListItem Text="1" Value="1"></asp:ListItem>

<asp:ListItem Text="1" Value="1"></asp:ListItem>

</asp:CheckBoxList>

</div>

</form>

</body>

</html>

No comments:

Post a Comment