Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i am trying to call my web service method ie:
C#
public Sample () {

[WebMethod]
public string CheckUserNameAvailability(string userName)
    {
        SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
        SqlDataAdapter dap = new SqlDataAdapter("select Email_Id from User_Registration where Email_Id='" + userName + "'", cn);
        DataSet ds = new DataSet();
        dap.Fill(ds);
        if (ds.Tables[0].Rows.Count != 0)
        {
            return "Name Already Exist";
        }
        else
        {
            return "Available";
        }
}
}

then I am trying to make reference of this method using scripts manager ie.
ASP.NET
<asp:ScriptManager ID="ScriptManager1" runat="server">
                    <services>
                    <asp:ServiceReference Path="~/Sample.asmx" />
                    </services>

but when i calling we method in javascript function then it can't be accessible there even i am using <%@import Namespace="System.Web.Services"%> on the top of aspx page

error:-Error updating JScript Intellisense

please give me the solution how cal i access my class easily in my .aspx page
Posted
Updated 3-May-12 2:23am
v3
Comments
Sandeep Mewara 3-May-12 7:15am    
Where is your JS call? How did you made that?
Vivek_Sharma 4-May-12 1:27am    
still i am facing problem with this web method in accessing it in javascript function

[WebMethod]
public static void ChangePass(string UserName,string AltEmail,string OldPass,string NewPass,string ComfPass)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
SqlDataAdapter sp = new SqlDataAdapter("select Password from User_Registration where Password='" + OldPass + "'", con);
DataSet ds = new DataSet();
sp.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
SqlDataAdapter dap = new SqlDataAdapter("update User_Registration set Password='" + ComfPass + "' where Email_Id='" + UserName + "'", con);
DataSet ds1 = new DataSet();
dap.Fill(ds1);
MailMessage mail = new MailMessage("tech@xyz.com", AltEmail);
mail.Body = "Email:-" + mail.From + "<br/>" + "New Password:-" + ComfPass;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetCre = new NetworkCredential();
NetCre.UserName = "tech@xyz.com";
NetCre.Password = "abc@123";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetCre;
smtp.Port = 587;
smtp.Send(mail);

}
}
Sandeep Mewara 4-May-12 2:36am    
Dude, where in Javascript you made a call to your webservice? Syntax? Line of action?

1 solution

Hi,
Use ajax call to hit the Webservice. you need to make your WebMethod static now

ajax call works like this:
JavaScript
function CheckUserNameAvailability(username) {
          try {
              $.ajax({
                  type: "POST",
                  url: "YourForm.aspx/CheckUserNameAvailability",
                  data: "{'userName':'" + username + "'}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function (msg) {
                      if (msg.d == "Available") {
                          alert('Available..........');
                      }
                  },
                  error: function () {
                      alert('Error occured!');
                  }
              });
          } catch (e) {
              alert(e);
          }
      }

Here replace your page name with YourForm.aspx in the url.
send value to parameter username when you call the Method in javascript as
ASP.NET
<asp:button id="btnCheckName" runat="server" onclientclick="return CheckUserNameAvailability('username');" xmlns:asp="#unknown" />
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900