Categories
Asp, Asp.net

CheckBoxList Validation Using JavaScript In Asp.Net

CheckBoxList Validation Using JavaScript In Asp.Net

In this tutorial i will teach you CheckBoxList Validation Using JavaScript In Asp.Net.We will put validation on CheckBoxList by using JavaScript.We have to write a function in JavaScript which will check all controls in loop.

Source Code:

01<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
02 
03<!DOCTYPE html>
04 
06<head runat="server">
07<title>CheckBoxList Validation Using JavaScript In Asp.Net</title>
08<style type="text/css">
09body
10{
11margin:0px auto;
12width:980px;
13font-family:Calibri;
14text-align:center;
15}
16h2
17{
18text-align:center;
19}
20</style>
21<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
22<script type="text/javascript">
23$(document).ready(function () {
24$('#Save').click(function () {
25if ($('#chk1 input:checked').length > 0) {
26return true;
27}
28else {
29alert('Error')
30return false;
31}
32})
33});
34 
35</script>
36 
37</head>
38<body>
39<form id="form1" runat="server">
40<h2>CheckBoxList Validation Using JavaScript In Asp.Net</h2>
41<div style="text-align:center;padding-left:300px">
42<asp:CheckBoxList ID="chk1" RepeatDirection="Horizontal" runat="server">
43<asp:ListItem Text="1" Value="1"></asp:ListItem>
44<asp:ListItem Text="2" Value="2"></asp:ListItem>
45<asp:ListItem Text="3" Value="3"></asp:ListItem>
46<asp:ListItem Text="4" Value="4"></asp:ListItem>
47<asp:ListItem Text="5" Value="5"></asp:ListItem>
48<asp:ListItem Text="6" Value="6"></asp:ListItem>
49<asp:ListItem Text="7" Value="7"></asp:ListItem>
50<asp:ListItem Text="8" Value="8"></asp:ListItem>
51<asp:ListItem Text="9" Value="9"></asp:ListItem>
52<asp:ListItem Text="10" Value="10"></asp:ListItem>
53</asp:CheckBoxList>
54<br /><br /></div>
55<asp:Button ID="Save" Text="Submit" runat="server" OnClick="Save_Click" />
56 
57</form>
58</body>
59</html>

One reply on “CheckBoxList Validation Using JavaScript In Asp.Net”

Comments are closed.