.aspx page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnSubmit').click(function () {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'insertDataThroughJsonjQuery.aspx/InsertMethod',
data: "{'Name':'" + document.getElementById('txtuname').value + "', 'Pwd':'" + document.getElementById('txtpwd').value + "','Email':'" + document.getElementById('txtemail').value + "'}",
async: false,
success: function (response) {
$('#txtuname').val('');
$('#txtpwd').val('');
$('#txtemail').val('');
$('#lblmsg').val('Inserted Sucessfully');
// alert("Record Has been Saved in Database");
},
error: function ()
{ console.log('there is some error'); }
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%">
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>
User Name :
</td>
<td>
<asp:TextBox ID="txtuname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<asp:TextBox ID="txtpwd" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email :
</td>
<td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</form>
</body>
</html>
.aspx.cs page
[WebMethod]
public static string InsertMethod(string Name, string Pwd, string Email)
{
SqlConnection con = new SqlConnection("connection string");
string s = "insert Query";
SqlCommand cmd = new SqlCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return "True";
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnSubmit').click(function () {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'insertDataThroughJsonjQuery.aspx/InsertMethod',
data: "{'Name':'" + document.getElementById('txtuname').value + "', 'Pwd':'" + document.getElementById('txtpwd').value + "','Email':'" + document.getElementById('txtemail').value + "'}",
async: false,
success: function (response) {
$('#txtuname').val('');
$('#txtpwd').val('');
$('#txtemail').val('');
$('#lblmsg').val('Inserted Sucessfully');
// alert("Record Has been Saved in Database");
},
error: function ()
{ console.log('there is some error'); }
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%">
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>
User Name :
</td>
<td>
<asp:TextBox ID="txtuname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<asp:TextBox ID="txtpwd" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email :
</td>
<td>
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</div>
</form>
</body>
</html>
.aspx.cs page
[WebMethod]
public static string InsertMethod(string Name, string Pwd, string Email)
{
SqlConnection con = new SqlConnection("connection string");
string s = "insert Query";
SqlCommand cmd = new SqlCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return "True";
}
No comments:
Post a Comment