Submit data into database Using of Ajax and Javascript

Posted by K011gusain89 under ASP.NET AJAX category on | Points: 40 | Views : 1607

<html xmlns="">
<head runat="server">
<script type="text/javascript">
function ok()
var name = document.getElementById("txtName1").value;
var user = document.getElementById("txtUser").value;
var pass = document.getElementById("txtpass1").value;
var email = document.getElementById("txtEmail").value;
PageMethods.entry(name, user, pass, email, callback);

function callback()
alert('data inserted');

<form id="form1" runat="server">
<asp:ScriptManager ID="mana" runat="server" EnablePageMethods ="true">
<p>Name<input type="text" id="txtName1" /></p>
<p>User ID<input type="text" id="txtUser" /></p>
<p>Password<input type="text" id="txtpass1" /></p>
<p>Email<input type="text" id="txtEmail" /></p>

<input type="button" id="btn1" value="submit" onclick="ok();"/>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;

namespace WebApplication3
public partial class ajax1 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

public static void entry(string name, string user, string pass, string email)
SqlConnection con = new SqlConnection("server=Servername;database=databasename;integrated security=true");
SqlCommand cmd = new SqlCommand("insert into TB_register values('" + name + "','" + user + "','" + pass + "','" + email + "','" + DateTime.Now + "')", con);

Comments or Responses

Posted by: Easwaran on: 10/22/2012 Level:Starter | Status: [Member] | Points: 10
Is this possible to create a [WebMethod] inside Page class? I hope for webservice, the base class should be System.Web.Services? Please do clarify.

Login to post response