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:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>CheckBoxList Validation Using JavaScript In Asp.Net</title>
<style type="text/css">
body
{
margin:0px auto;
width:980px;
font-family:Calibri;
text-align:center;
}
h2
{
text-align:center;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#Save').click(function () {
if ($('#chk1 input:checked').length > 0) {
return true;
}
else {
alert('Error')
return false;
}
})
});

</script>

</head>
<body>
<form id="form1" runat="server">
<h2>CheckBoxList Validation Using JavaScript In Asp.Net</h2>
<div style="text-align:center;padding-left:300px">
<asp:CheckBoxList ID="chk1" RepeatDirection="Horizontal" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
<asp:ListItem Text="5" Value="5"></asp:ListItem>
<asp:ListItem Text="6" Value="6"></asp:ListItem>
<asp:ListItem Text="7" Value="7"></asp:ListItem>
<asp:ListItem Text="8" Value="8"></asp:ListItem>
<asp:ListItem Text="9" Value="9"></asp:ListItem>
<asp:ListItem Text="10" Value="10"></asp:ListItem>
</asp:CheckBoxList>
<br /><br /></div>
<asp:Button ID="Save" Text="Submit" runat="server" OnClick="Save_Click" />

</form>
</body>
</html>

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

Comments are closed.