Autocompleteextender not working

You want to know why even though you followed the rulebook your autocompleteextender just won’t make a call to your webservice? Read on…

So you want to use the autocompleteextender that comes with the AjaxControlToolkit. You go to the demo site (www.ajaxcontroltoolkit.com) and follow their extact instructions.

Place a nice textbox on your page like so:

<asp:TextBox id="txtMyTextBox" runat="server" />

With a good scriptmanager like so:

<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="MyWebService.asmx" />
</Services>
</asp:ScriptManager>

and your beloved autocompleteextender like so:

<cc1:AutoCompleteExtender ID="autocompleteextender1" runat="server" TargetControlID="txtMyTextBox"
ServiceMethod="MyWebMethod" ServicePath="MyWebService.asmx"
UseContextKey="true" CompletionSetCount="10" EnableViewState="false"></cc1:AutoCompleteExtender>

You have your code behind as simple as can be:

[System.Web.Script.Services.ScriptService]
public class UtilityService : System.Web.Services.WebService
{
[WebMethod(EnableSession = true)]
public string[] GetCustomerList(string prefix, int count)
{
  //Your code to return a string[] list goes here;
}
}

You run your code waiting for the magic to happen, but nothing does. So you think your webmethod is not returning the list it should. Want to debug it? Go ahead and place a breakpoint, I’ll wait. Did it break?

If it did, then you are lucky and you followed their website to the T (which also means your problem is not what I’m writing about). If it didn’t, then here is your problem…

Your method signature should be:

public string[] MyMethod(string prefixText, int count)

NOT

public string[] MyMethod(string anyothervariable, int count)

Your variable HAS to be called “prefixText

I thought it was strange as well, and I wasted 2 hours trying to figure that out. Its frustating as hell!

11 Comments

d2November 23rd, 2008 at 11:48 am

thanks for your explaination. I spent hours to figure out what is that i did wrong. only to learn that param name should be what they want!!! very strange.

KeithDecember 10th, 2008 at 11:31 pm

THANK YOU!!! I just spent half of my day trying to figure this out. I can’t believe how ridiculous that is. Anyway thanks so much.

ThiFebruary 4th, 2009 at 2:40 pm

THANK YOU VERY VERY MUCH!!!!

SatinderJuly 6th, 2009 at 4:52 am

Also don’t forget to include
[system.web.script.services.scriptservices]
Before defining the web service class

Vivek GuptaAugust 26th, 2009 at 3:46 am

Thanks
Its lot of helpful to me also.I was also facing the same problem in AutoCompleteExtender. I doesnot believe that param create these type of major problem.
Anyway a lot of thanks to you….

ChiragAugust 31st, 2009 at 2:29 am

Thanks for your suggestions.
its really worth.
I have spend 6-7 hrs.
Thank you sir…

premOctober 9th, 2009 at 9:17 am

thanks buddy,by ur help i solve the issue

Alan SimesOctober 27th, 2009 at 8:41 am

That took me two solid days, I had renamed it too PrefixText, this is just insane

Haitham OwaisDecember 17th, 2009 at 4:33 am

Look guys, here is the solution

The string array return web method should satisfy the following conditions

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

Note that you can replace “GetCompletionList” with a name of your choice, but the return type and parameter name and type must exactly match, including case.

wish that will solve your problem.

Kind Regards,
Haitham Owais

TeetoJanuary 7th, 2010 at 1:39 am

ONE MORE VERY IMPORTANT NOTE:

Please also check whether AutoCompleteExtender’s version is valid or not for the version of your Visual Studio :)

ShivJanuary 21st, 2010 at 6:46 pm

Thanks a lot Ramesh,… your blog helped me after wasting hours on this issue… Can you give me some pointers why is it so?

Leave a comment

Your comment