My $("#form1").validate({}); is not working
My MarkUp
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="_Default.aspx.cs" Inherits="WebApplication1._3_Tier._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Insert Records into DataBase</title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../Scripts/a.js" type="text/javascript"></script>
<script src="../Scripts/jquery.validate.min.js" type="text/javascript"></script>
</head>
<body>
<h3>
Demo: 3-Tier Architecture</h3>
<form id="form1" runat="server">
<div>
<p>
<a href="List.aspx">List Records</a></p>
<asp:Label ID="lblMessage" runat="Server" ForeColor="red" EnableViewState="False"></asp:Label>
<table style="border: 2px solid #cccccc;">
<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="AddRecords" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
My JS
$(document).ready(function () {
var firstname = $('#txtFirstName').val();
$("#form1").validate({
rules: {
firstname: {
required: true,
}
},
messages: {
firstname: {
required: "Please provide your firstname",
}
}
});
});
I took help of this this post
JQuery Validation is not validating
I Tried to rectify My Code ..Still after that it is not working
this is generated HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<style type="text/css">
body
{
font-family: Arial, Trebuchet Ms;
font-size: 10pt;
}
</style>
<title>
Insert Records into DataBase
</title>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../Scripts/a.js" type="text/javascript"></script>
<script src="../Scripts/jquery.validate.min.js" type="text/javascript"></script>
</head>
<body>
<h3>
Demo: 3-Tier Architecture</h3>
<form method="post" action="_Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMjEzNDcyMDczZGQt6WgCuARQGKOLro6pdjwaUvt/QFoxwH5v1RzCNAUj7w==" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAX8Nm0IHiD/KCZocX+BlM2eTNr8+Dx/H+2fNfPhxgyex+tZBdiRon5d1qE03oo5TvNalnLgDFTt8y4U1Y3swfOyPOaW1pQztoQA36D1w/+bXdBIngoW+rlnKfoMZ3QFO1yNN5iBqFwWfHPEKsfQ/9eW" />
</div>
<div>
<p>
<a href="List.aspx">List Records</a></p>
<span id="lblMessage" style="color:Red;"></span>
<table style="border: 2px solid #cccccc;">
<tr style="background-color: #507CD1; color: White;">
<th colspan="3">
Add Records
</th>
</tr>
<tr>
<td>
First Name:
</td>
<td>
<input name="txtFirstName" type="text" id="txtFirstName" />
</td>
</tr>
<tr>
<td>
Last Name:
</td>
<td>
<input name="txtLastName" type="text" id="txtLastName" />
</td>
</tr>
<tr>
<td>
Age:
</td>
<td>
<input name="txtAge" type="text" size="4" id="txtAge" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="btnSubmit" value="Submit" id="btnSubmit" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
I tried to run on http://jsfiddle.net/7T7ZX/ ...it is not working
I am debugging on Firebug . it is debugging fine there .
Please suggest