Ok, step 1:
Make your WebService. In your project, create a folder called
Services, (not a necessity, but neat :P) Right click and say Add -> New Web Service. Lets call it WSAutoComplete. Now make it look like this:
namespace Services
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WSAutoComplete : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public string[] GetAutoCompleteList(string prefixText, int count)
{
return GetResults(prefixText, count);
}
}
private string[] GetResults(prefixText, count)
{
List<string> items = new List<string>() {"bob", "steve", "jones", "andrew"};
List<string> result = new List<string();>
foreach (string s in items)
if (s.StartsWith(prefixText))
result.Add(s);
return result.ToArray();
}</string></string></string>
(Ignore this </string></string></string>, I dont know why thats there being generated by the text editor???)
I purposely left out the count for time purposes, you can add that yourself, just limit the amount of results that you return.
Now, on you AutoCompleteExtender control:
<asp:TextBox id="txtMyTextBox" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender TargetControlID="txtMyTextBox" ServicePath="/Services/WSAutoComplete.asmx"CompletionInterval="500" MinimumPrefixLength="2" ServiceMethod="GetResults"
ID="autocomplete" runat="server"></asp:AutoCompleteExtender>
That should work 100%!!! Make sure you set up your service path correctly! Put a break point inside you service method and see if it gets hit! If it doesnt, then there is probably a problem with your ServicePath or ServiceMethod paramter