I'm going on my 3rd day trying to get my Ajax AutoComplete textbox to call my web method. Based on my google searches, I'm not alone. I suspect the problem has something to do with the ServicePath property on the extender, although I'm not sure. My
web service is at the same level, on the same server as my test web page. I'm not sure exactly what should go into the ServicePath property, although I think I've tried every possibility. Below is my web service followed by my script. Thanks for any clues
or help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using AjaxControlToolkit;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Collections.Specialized;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{
public string[] AutoCompleteNames(string prefixText, int count)
{
System.Data.SqlClient.SqlConnection cxn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["HumanResourcesConnectionString"].ConnectionString);
cxn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select distinct Name from LU_PAID where Name like 'A%'";
cmd.Connection = cxn;
SqlDataReader dr = cmd.ExecuteReader();
List<string> liste = new List<string>();
while (dr.Read())
{
liste.Add((string)dr.GetString(0));
}
return liste.ToArray();
}
How does Relative work, when you're running from Visual Studio and not from the folder where the aspx file is published to? Also I don't understand most of the examples I see where ServicePath is set to something like (for example),
ServicePath="CarsService.asmx".
That's the name of the asmx file, but it's not the name of the web service, is it? It my case, under wwwroot, I have my folder called HRWebService, with a file called Service.asmx. I can get to my web service using:
http://vhabrksql2/HRWebService/Service.asmx. And I can get to my application with
http://vhabrksql2/CreateAwards/. So in this case, what do I put in ServicePath? Is it "../HRWebService/Service.asmx"?
If my use of ServicePath is not the problem, what else could it be?
No, it doesn't call the webservice with ServicePath="~/HRWebService/Service.asmx". So maybe ServicePath is not the problem. Is there any way to get more clues about what's going on? I know I have the web service signature set up correctly, as shown above.
Put a breakpoint in your webmethod to see if it's being called. If it's still not working, maybe try using a <ScriptManager> instead of <ToolkitScriptManager>.
Interesting. I'm not sure. Maybe you've installed the wrong version of the ACT(?) based on the version of visual studio & the framework you're targetting. Do any of the ACT extenders work for you? Can you get the watermark extender to work? It's simple
to test it out quickly... Otherwise, I'm all out of ideas.
It seems that you use the New version 40412 of the AjaxControlToolkit. If so, please replace the ScriptManager with the AjaxControlToolkit ToolkitScriptManager.
Best regards,
Zhi-Qiang Ni
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
DaveBF
Member
66 Points
154 Posts
Trying to get AutoComplete to call my Web Service
Apr 26, 2010 02:28 PM|LINK
I'm going on my 3rd day trying to get my Ajax AutoComplete textbox to call my web method. Based on my google searches, I'm not alone. I suspect the problem has something to do with the ServicePath property on the extender, although I'm not sure. My web service is at the same level, on the same server as my test web page. I'm not sure exactly what should go into the ServicePath property, although I think I've tried every possibility. Below is my web service followed by my script. Thanks for any clues or help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using AjaxControlToolkit;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using System.Collections.Specialized;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] AutoCompleteNames(string prefixText, int count)
{
System.Data.SqlClient.SqlConnection cxn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["HumanResourcesConnectionString"].ConnectionString);
cxn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select distinct Name from LU_PAID where Name like 'A%'";
cmd.Connection = cxn;
SqlDataReader dr = cmd.ExecuteReader();
List<string> liste = new List<string>();
while (dr.Read())
{
liste.Add((string)dr.GetString(0));
}
return liste.ToArray();
}
}
-----------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AutoExtenderTest._Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
ServiceMethod="AutoCompleteNames" ServicePath="HRWebService/Service.asmx"
TargetControlID="TextBox1">
</ajax:AutoCompleteExtender>
</div>
</form>
</body>
</html>
ajax Autcomplete
MetalAsp.Net
All-Star
112075 Points
18242 Posts
Moderator
Re: Trying to get AutoComplete to call my Web Service
Apr 26, 2010 03:24 PM|LINK
Maybe use the ~ (relative to root) in the ServicePath since you suspect it's the problem.
DaveBF
Member
66 Points
154 Posts
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 11:10 AM|LINK
How does Relative work, when you're running from Visual Studio and not from the folder where the aspx file is published to? Also I don't understand most of the examples I see where ServicePath is set to something like (for example), ServicePath="CarsService.asmx".
That's the name of the asmx file, but it's not the name of the web service, is it? It my case, under wwwroot, I have my folder called HRWebService, with a file called Service.asmx. I can get to my web service using: http://vhabrksql2/HRWebService/Service.asmx. And I can get to my application with http://vhabrksql2/CreateAwards/. So in this case, what do I put in ServicePath? Is it "../HRWebService/Service.asmx"?
If my use of ServicePath is not the problem, what else could it be?
MetalAsp.Net
All-Star
112075 Points
18242 Posts
Moderator
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 12:10 PM|LINK
Does it work with this? ServicePath="~/HRWebService/Service.asmx". ~ means relative to the root of your website.
DaveBF
Member
66 Points
154 Posts
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 12:22 PM|LINK
No, it doesn't call the webservice with ServicePath="~/HRWebService/Service.asmx". So maybe ServicePath is not the problem. Is there any way to get more clues about what's going on? I know I have the web service signature set up correctly, as shown above.
MetalAsp.Net
All-Star
112075 Points
18242 Posts
Moderator
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 12:31 PM|LINK
Put a breakpoint in your webmethod to see if it's being called. If it's still not working, maybe try using a <ScriptManager> instead of <ToolkitScriptManager>.
DaveBF
Member
66 Points
154 Posts
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 12:56 PM|LINK
I've been putting a breakpoint in the web service, and it doesn't get called.
My ajax tagprefix is "ajax"
If I switch to ScriptManager, should it be asp:ScriptManager or ajax:ScriptManager?
If I use ajax:ScriptManager, I get ScriptManager is not a known element.
If I use asp:ScriptManager, I get a runtime error saying "AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts...."
MetalAsp.Net
All-Star
112075 Points
18242 Posts
Moderator
Re: Trying to get AutoComplete to call my Web Service
Apr 27, 2010 01:28 PM|LINK
Interesting. I'm not sure. Maybe you've installed the wrong version of the ACT(?) based on the version of visual studio & the framework you're targetting. Do any of the ACT extenders work for you? Can you get the watermark extender to work? It's simple to test it out quickly... Otherwise, I'm all out of ideas.
Zhi-Qiang Ni...
All-Star
33491 Points
2952 Posts
Microsoft
Re: Trying to get AutoComplete to call my Web Service
Apr 30, 2010 11:18 AM|LINK
Hi DaveBF,
It seems that you use the New version 40412 of the AjaxControlToolkit. If so, please replace the ScriptManager with the AjaxControlToolkit ToolkitScriptManager.
Best regards,
Zhi-Qiang Ni
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
DaveBF
Member
66 Points
154 Posts
Re: Trying to get AutoComplete to call my Web Service
May 03, 2010 02:20 PM|LINK
Zhi-Qiang,
Could you give me some more details? I already have
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
in my script. What should I try changing? It might be that I have a problem with Ajax versions. I don't know.
Thanks.