<title></title>
<link href="css/table.css" rel="Stylesheet" type="text/css" />
//
<script type="text/jscript">
$(document).ready(function () {
$("#btnRegister").click(function () {
var Name = $("#txtName").val();
var Password = $("#txtPassword").val();
var sex = $("#txtSex").val();
var Age = $("#txtAge").val();
var ContactNo = $("txtContactNo").val();
var country = $("#txtCountry").val();
var Email = $("#txtEmail").val();
var pattern = /^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*@[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/;
if (Name == "" || Password == "" || sex == "" || Age == "" || country == "" || Email == "")
alert('Pleas fill up all field:');
else {
if (pattern.test(Email)) {
$.ajax({
type: "Post",
url: "Handler.ashx?Name=" + Name + "&Password=" + Password + "&Sex=" + sex + "&Age=" + Age + "&ContactNo=" +ContactNo+ "&Country=" + country + "&Email=" + Email + "",
data: "text/plain",
success: function (data) {
alert(data);
$("#txtName").val('');
$("#txtPassword").val('');
$("#txtSex").val('');
$("#txtAge").val('');
$("#txtContactNo").val('');
$("#txtCountry").val('');
$("#txtEmail").val('');
}
});
}
else
alert('please insert valid email Id:');
}
});
});
</script>
</head>
<body>
<form id="form2" runat="server" method="post">
<asp:ScriptManager ID="scptMgr" runat="server"></asp:ScriptManager>
<div>
<table class="tab">
<tr>
<td class="col">
<span>Name :</span>
</td>
<td class="col">
<input type="text" id="txtName" />
</td>
</tr>
<tr>
<td class="col">
<span>Password :</span>
</td>
<td class="col">
<input type="password" id="txtPassword" />
</td>
</tr>
<tr>
<td class="col">
<span>Sex :</span>
</td>
<td class="col">
<input type="text" id="txtSex" />
</td>
</tr>
<tr>
<td class="col">
<span>Age</span>
</td>
<td class="col">
<input type="text" id="txtAge" />
</td>
</tr>
<tr>
<td class="col">
<span>ContactNo:</span>
</td>
<td class="col">
<input type="text" id="txtContactNo" />
</td>
</tr>
<tr>
<td class="col">
<span>Country :</span>
</td>
<td class="col">
<input type="text" id="txtCountry" />
</td>
</tr>
<tr>
<td class="col">
<span>Email :</span>
</td>
<td class="col">
<input type="text" id="txtEmail" />
</td>
</tr>
<tr>
<td class="col">
</td>
<td class="col">
<input type="button" id="btnRegister" value="Register" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Css file:-
body {
}
.tab
{
width:400px;
height:auto;
background-color:#666;
color:White;
font-size:medium;
}
.col
{
width:200px;
height:10px;
background-color:Red;
/*text-align:center;*/
}
.col1
{
width:100px;
height:10px;
background-color:Aqua;
font-size:large;
color:Blue;
}
.col2
{
width:100px;
height:10px;
background-color:#303030;
border-color:Blue;
}
Data connection:-
public class DataConnection
{
public DataConnection()
{
//
// TODO: Add constructor logic here
//
}
public static string constr = @"Data Source=AJIT\AJIT;Initial Catalog=Job;persist Security Info=True;User Id=sa;Password=sap";
}
Handler.ashx
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class Handler : IHttpHandler {
SqlConnection con = new SqlConnection(DataConnection.constr);
public void ProcessRequest(HttpContext context) {
string Name = context.Request.QueryString["Name"].ToString();
string Password = context.Request.QueryString["Password"].ToString();
string Sex = context.Request.QueryString["Sex"].ToString();
string Age = context.Request.QueryString["Age"].ToString();
string ContactNo = context.Request.QueryString["ContactNo"].ToString();
string Country = context.Request.QueryString["Country"].ToString();
string Email = context.Request.QueryString["Email"].ToString();
SqlCommand cmd = new SqlCommand("INSERT INTO Posting Values(@Name,@Password,@Sex,@Age,@ContactNo,@Country,@Email)", con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@Sex", Sex);
cmd.Parameters.AddWithValue("@Age", Age);
cmd.Parameters.AddWithValue("@ContactNo", ContactNo);
cmd.Parameters.AddWithValue("@Country", Country);
cmd.Parameters.AddWithValue("@Email", Email);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i == 1)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Data is insert successfully");
}
}
public bool IsReusable {
get {
return false;
}
}
}
//Handler:-ASP.NET handles all the
<link href="css/table.css" rel="Stylesheet" type="text/css" />
//
<script type="text/jscript">
$(document).ready(function () {
$("#btnRegister").click(function () {
var Name = $("#txtName").val();
var Password = $("#txtPassword").val();
var sex = $("#txtSex").val();
var Age = $("#txtAge").val();
var ContactNo = $("txtContactNo").val();
var country = $("#txtCountry").val();
var Email = $("#txtEmail").val();
var pattern = /^[a-zA-Z0-9\-_]+(\.[a-zA-Z0-9\-_]+)*@[a-z0-9]+(\-[a-z0-9]+)*(\.[a-z0-9]+(\-[a-z0-9]+)*)*\.[a-z]{2,4}$/;
if (Name == "" || Password == "" || sex == "" || Age == "" || country == "" || Email == "")
alert('Pleas fill up all field:');
else {
if (pattern.test(Email)) {
$.ajax({
type: "Post",
url: "Handler.ashx?Name=" + Name + "&Password=" + Password + "&Sex=" + sex + "&Age=" + Age + "&ContactNo=" +ContactNo+ "&Country=" + country + "&Email=" + Email + "",
data: "text/plain",
success: function (data) {
alert(data);
$("#txtName").val('');
$("#txtPassword").val('');
$("#txtSex").val('');
$("#txtAge").val('');
$("#txtContactNo").val('');
$("#txtCountry").val('');
$("#txtEmail").val('');
}
});
}
else
alert('please insert valid email Id:');
}
});
});
</script>
</head>
<body>
<form id="form2" runat="server" method="post">
<asp:ScriptManager ID="scptMgr" runat="server"></asp:ScriptManager>
<div>
<table class="tab">
<tr>
<td class="col">
<span>Name :</span>
</td>
<td class="col">
<input type="text" id="txtName" />
</td>
</tr>
<tr>
<td class="col">
<span>Password :</span>
</td>
<td class="col">
<input type="password" id="txtPassword" />
</td>
</tr>
<tr>
<td class="col">
<span>Sex :</span>
</td>
<td class="col">
<input type="text" id="txtSex" />
</td>
</tr>
<tr>
<td class="col">
<span>Age</span>
</td>
<td class="col">
<input type="text" id="txtAge" />
</td>
</tr>
<tr>
<td class="col">
<span>ContactNo:</span>
</td>
<td class="col">
<input type="text" id="txtContactNo" />
</td>
</tr>
<tr>
<td class="col">
<span>Country :</span>
</td>
<td class="col">
<input type="text" id="txtCountry" />
</td>
</tr>
<tr>
<td class="col">
<span>Email :</span>
</td>
<td class="col">
<input type="text" id="txtEmail" />
</td>
</tr>
<tr>
<td class="col">
</td>
<td class="col">
<input type="button" id="btnRegister" value="Register" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Css file:-
body {
}
.tab
{
width:400px;
height:auto;
background-color:#666;
color:White;
font-size:medium;
}
.col
{
width:200px;
height:10px;
background-color:Red;
/*text-align:center;*/
}
.col1
{
width:100px;
height:10px;
background-color:Aqua;
font-size:large;
color:Blue;
}
.col2
{
width:100px;
height:10px;
background-color:#303030;
border-color:Blue;
}
Data connection:-
public class DataConnection
{
public DataConnection()
{
//
// TODO: Add constructor logic here
//
}
public static string constr = @"Data Source=AJIT\AJIT;Initial Catalog=Job;persist Security Info=True;User Id=sa;Password=sap";
}
Handler.ashx
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class Handler : IHttpHandler {
SqlConnection con = new SqlConnection(DataConnection.constr);
public void ProcessRequest(HttpContext context) {
string Name = context.Request.QueryString["Name"].ToString();
string Password = context.Request.QueryString["Password"].ToString();
string Sex = context.Request.QueryString["Sex"].ToString();
string Age = context.Request.QueryString["Age"].ToString();
string ContactNo = context.Request.QueryString["ContactNo"].ToString();
string Country = context.Request.QueryString["Country"].ToString();
string Email = context.Request.QueryString["Email"].ToString();
SqlCommand cmd = new SqlCommand("INSERT INTO Posting Values(@Name,@Password,@Sex,@Age,@ContactNo,@Country,@Email)", con);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@Sex", Sex);
cmd.Parameters.AddWithValue("@Age", Age);
cmd.Parameters.AddWithValue("@ContactNo", ContactNo);
cmd.Parameters.AddWithValue("@Country", Country);
cmd.Parameters.AddWithValue("@Email", Email);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i == 1)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Data is insert successfully");
}
}
public bool IsReusable {
get {
return false;
}
}
}
//Handler:-ASP.NET handles all the
HTTP
requests coming from the user
and generates the appropriate response for it. ASP.NET framework knows
how to process different kind of requests based on extension, for
example, It can handle request for .aspx, .ascx and .txt
files, etc. When it receives any request, it checks the extension to
see if it can handle that request and performs some predefined steps to
serve that request.