aditya immadi

aditya immadi

  • NA
  • 215
  • 24k

ajax calls for checking existing email or name

Jun 13 2016 3:13 AM
Hai all i wrote this for calling rmail is exists or not in my db
 
$(document).ready(function () {
function NameChecking() {
var name= $("#<%=TxtName.ClientID%>").value;
alert(name)
$.ajax({
type: "POST",
url: "Default.aspx/CheckEmail",
data: '{Name: "' + $("#<%=TxtName.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
}
});
 
}
  <asp:TextBox ID="TxtName" runat="server" onchange="NameChecking();" AutoPostBack="false" CausesValidation="True" ClientIDMode="Static"></asp:TextBox>
 
and mmy .cs file is
[System.Web.Services.WebMethod]
public static string CheckEmail(string Name)
{
string s = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
string result = "";
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("SP_CheckName", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Name", Name);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
result = "true";
}
else
{
result = "false";
}
return result;
 
but the method namechecking is not firing which is in textbox control
 
any leads..
 
TIA 
 
 
 
 

Answers (4)