siva nathan

siva nathan

  • 880
  • 819
  • 218.1k

My Asp.net Reg form validation was not working using jquery

Jun 11 2017 5:55 AM
 below i'm posting my code it was not validating asp.net web form why?
 
webform1.aspx code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-3.2.1.js"></script>
<script>
$(document).ready(function () {
$("btn_Save").click(function () {
var Name, Email, Phone, Gender;
Name = $("#txt_Name").val();
Email = $("#txt_Email").val();
Phone = $("#txt_Phone").val();
Gender = $("#drp_Gender").val();
if (Name == "" && Email == "" && Phone == "" && Gender == "") {
alert("Enter All Fileds");
return false;
}
if (Name == "") {
alert("Enter Name");
return false;
}
if (Email == "") {
alert("Enter Email");
return false;
}
if (Phone == "") {
alert("Enter phone no");
return false;
}
if (Gender == 0) {
alert("Select Gender");
return false;
}
return true;
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Name:</td>
<td><asp:TextBox ID="txt_Name" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="auto-style1">Email:</td>
<td class="auto-style1"><asp:TextBox ID="txt_Email" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Phone:</td>
<td><asp:TextBox ID="txt_Phone" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:DropDownList ID="drp_Gender" runat="server">
<asp:ListItem Value="0">-Select-</asp:ListItem>
<asp:ListItem Value="1">Male</asp:ListItem>
<asp:ListItem Value="2">Female</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td></td>
<td>
<asp:Button id="btn_Save" runat="server" Text="Save" OnClick="btn_Save_Click"/>
<asp:Button id="btn_Cance" runat="server" Text="Cancel"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
webform2.aspx.cs code:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Data Entered Sucessfully");
}
 
 

Answers (2)