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!
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.
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.
THANK YOU VERY VERY MUCH!!!!
Also don’t forget to include
[system.web.script.services.scriptservices]
Before defining the web service class
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….
Thanks for your suggestions.
its really worth.
I have spend 6-7 hrs.
Thank you sir…
thanks buddy,by ur help i solve the issue
That took me two solid days, I had renamed it too PrefixText, this is just insane
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
ONE MORE VERY IMPORTANT NOTE:
Please also check whether AutoCompleteExtender’s version is valid or not for the version of your Visual Studio
Thanks a lot Ramesh,… your blog helped me after wasting hours on this issue… Can you give me some pointers why is it so?