- Move the service method from the class to a web service (I already had one so I added it to that). Make sure that the web service is marked with [ScriptService] and the method with [ScriptMethod] I also marked it as [WebMethod] just for fun.
- This method when in a web service MUST be non-static and although it can have any name, it MUST return a string or List
and MUST have two parameters that are of the type AND NAME: string prefixText, int count since the reflection system uses the names to look these up (messy but that is how it is!)
- For some reason I couldn't use a server tag to insert the unique ID of my text box control into the TargetControlID of the autocomplete control since it would be mangled inside a master page. I therefore added the code: autoCompleteExtender1.TargetControlID = enterSearchNumber.UniqueID; into the Page_Load method inside my user control. This is NOT inside if (!IsPostBack) so that it links every time.
- I created an event in the user control that is fired when the user presses a "Load" button using the normal EventArgs type technique and which returns the selected object in the event args.
- I set the ServicePath property of the autocompleteextender inside my UserControl to (in my case) servicepath="~/Quotation/BusinessLogicAccess.asmx" and also obviously set the servicemethod property to the name of the function.
- Then since it is used inside an UpdatePanel for Ajax, I had to add the following inside my ScriptManager:
Wednesday, 17 February 2010
Ajax Control Toolkit AutoCompleteExtender problems
I have used this autocomplete control and to be honest it seemed to work pretty much as expected. However, I had originally coded it into a specific page and wanted to make it into an asp.net user control so I could use it all over the place. I had problems though so here are the things I had to do to make it work: