VerySimple Developer Blog
Technical Tips, Tricks and Rants.
 
Apr
18
Filed Under (.NET, Announcements) by Jason on 18-04-2007

I recently had some trouble with the .NET AJAX Toolkit AutoComplete Extender which did not seem to be working despite copying all of the code directly from the documentation. I discovered two missing pieces that were not obvious (to me at least).

The first is that I was trying to use a ServiceMethod without a ServicePath - according to the documentation this should allow using a method within the same aspx page as the callback method. I would imagine that this could work however getting the aspx page to act as a web service wasn’t critical for my purposes and so I didn’t try very hard to get it working. Instead I wrote a separate web service class for the callback as is shown in the documentation.

The second issue had to do with the .NET attributes that must be included. The documentation provides the following example for the method (note the “WebMethod” and “ScriptMethod” attributes):


[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
Public string[] GetCompletionList(string prefixText, int count) { … }

What is less obvious, however, is that the web service class is required to have an attribute as well. A “ScriptService” attribute is require like so:

[WebService(Namespace = "http://www.verysimple.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService

I found this useful bit of info in the development forums but it would have saved me about four hours of suffering if it was just included on the example page. Simply adding this attribute solved all of my problems and the autocomplete extender worked perfectly

In the process of solving this error, I used a handy utility by the name of Fiddler which allows you to spy on all of the HTTP traffic. I had initially suspected that the autocomplete javascript was simply not making the AJAX post because I couldn’t detect any activity using a javascript debugger and no javascript exceptions were being thrown. Using Fiddler, I saw the post was in fact being made. This is extremely useful for AJAX applications because you can see the raw output of the web service as it is being requested - which in my case contained some run-time errors. The autocomplete control seem to just quietly choke when the webservice fails.

One thing to note about Fiddler is that, though it works with any browser, only IE works right out of the box without some manual configuration. I put my other browser away for a bit and used IE. Another useful tip is that Fiddler didn’t seem to intercept traffic when using “localhost” as the hostname. When I used my local IP address, however, (for example 192.168.1.25) it worked perfectly.

Please feel free to post any comments. In particular I would be interested to know if you are able to use the aspx page as the ServiceMethod without creating a separate web service.

 

Comments:
18 Comments posted on "AJAX Toolkit AutoComplete Extender not Firing"
Nishanth Nair on June 1st, 2007 at 2:06 am #

Methods that are exposed to JavaScript from pages are called PageMethods. By default, this isn’t enabled. You have to enable it from the ScriptManager:

Also, the ServicePath for the AutoCompleteExtender should point to the ulr of the page:


Nishanth Nair on June 1st, 2007 at 2:07 am #

I tried to post the sample code, but i think the blog does not accpet XML ???


Nishanth Nair on June 1st, 2007 at 2:14 am #

insert EnablepageMethods=”true” inside script manager.


Jason on June 1st, 2007 at 5:34 pm #

Thanks Nishanth - I’m going to try that out. I like the idea of having a single webform, and the methods that it requires via AJAX are also contained within that same class. For little things like populating a combo box or something it seems like a nice option for keeping things organized.


Priya Khisti on July 3rd, 2007 at 4:34 pm #

Very useful!! saved me couple of hours of debuging


shivesh on August 2nd, 2007 at 9:36 am #

I want to use pagemethod but unable to do so. ScriptManager does not have property as EnablePageMethod. Please help , how can i call a page method in servicepath of DynamicPopulateEstender.


Robert Williamson on August 14th, 2007 at 2:18 pm #

Good afternoon!! I read your article - good tips - I was not able to eliminate the webservice - I followe all the steps listed - any ideas?? Please let me know - Thanks!!


Noran on October 4th, 2007 at 6:40 am #

Thanks! I spent the whole day yesterday trying to figure this out =D


Kalam on November 30th, 2007 at 12:33 am #

Thanks you saved my time. By adding
[System.Web.Script.Services.ScriptService]
this property it worked


Tushar on December 25th, 2007 at 9:58 pm #

Why am i unable to access
System.Web.Script.Services.ScriptService

am i missing a reference??


Tushar on December 25th, 2007 at 10:04 pm #

Gottcha!!!

I added a reference to System.Web.Extensions

Now i could access
System.Web.Script.Services.ScriptService


Fredric on December 27th, 2007 at 6:52 am #

Tnx, saved me a lot of work :-)


Johhnie on February 10th, 2008 at 10:12 am #

Thank you thank you thank you! :)


Vijay on March 14th, 2008 at 4:20 am #

I have seen an article. That explains this. Below is the url of the article. http://www.cool-tips.net/autocompleteextender.aspx Plz go thru it. Hope it will help.


Michael on March 26th, 2008 at 1:55 am #

Also MAKE SURE to delete the “static” keyword, when moving a Script Method embedded in ASPX file, to a web service.


Anonymous on April 27th, 2008 at 8:19 am #

Thank you, this was eating me…


SibyGeorge on May 28th, 2008 at 4:00 am #

Hi,
Thanks, it worked and saved a lot of time.Thanks a lot.I was missing the attribute [System.Web.Script.Services.ScriptService]in my webservice class.


Sebastian on June 18th, 2008 at 12:14 pm #

Thank you very much, this saved me a lot of work :D


Post a comment

Name: 
Email: 
URL: 
Comments: 
Close
  • Social Web

NOTE: Email is disabled

E-mail It