<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication10._Default" %> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <script type="text/javascript"> $(document).ready(function () { $("#userinput").on('input', function () { if ($(this).val().length >= 8) { $.ajax({ type: "POST", url: "Default.aspx/fillfields", contentType: "application/json; charset=utf-8", data: '{employeeID: "' + $("#userinput").val() + '"}', dataType: "json" }); $('#userinput').val(""); } }); }); </script> <br> <div style="text-align: center"> <br> <input autofocus="autofocus" id="userinput" /> <br> <hr> </div>
using System; using System.Web.UI; using System.Data.SqlClient; using System.Configuration; namespace WebApplication10 { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod] public static void fillfields(string employeeID) { string constr = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; using (SqlConnection connection = new SqlConnection(constr)) { connection.Open(); using (SqlCommand command = new SqlCommand("TMS_INSERT", connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@EMP_ID", employeeID); command.ExecuteNonQuery(); } connection.Close(); } } } }
if ($(this).val().length >= 8)
"_"
url: "_Default.aspx/fillfields",
Quote:You are using This code which is wrong :- data: '{employeeID: "' + $("#userinput").val() + '"}', Correct code is here:- data: "{employeeID: '" + $("#userinput").val() + "'}", *Note:- You must watch the Quotes places. Thank You
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)