For two days I’ve been trying to figure out why I can’t possible make the autocomplete work.  Well, here’s the code that works using a db backend.  Of course you’ll need to create your own dataset with the correct method…here’s my sql method in the dataset.

SELECT        TOP (@count) id, contactName, businessName, phone, email, website
FROM            tbl_clients
WHERE        (businessName LIKE @prefixText+ N’%’)

//clientBLL.cs for access to dataset
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

/// 
///
 Summary description for clientsBLL
/// 
///
 
[System.ComponentModel.DataObject]
public class clientsBLL
{

    private DataSet1TableAdapters.tbl_clientsTableAdapter _adapter = null;

    public DataSet1TableAdapters.tbl_clientsTableAdapter Adapter
    {
        get
        {
            if (_adapter == null)
                _adapter = new DataSet1TableAdapters.tbl_clientsTableAdapter();
            return _adapter;
        }
    }


    [DataObjectMethod(DataObjectMethodType.Select, true)]
    public DataSet1.tbl_clientsDataTable getClients()
    {
        return Adapter.GetData();
    }

    [DataObjectMethod(DataObjectMethodType.Select, false)]
    public DataSet1.tbl_clientsDataTable getClients(string prefixText)
    {
        return Adapter.GetDataByBusiness(prefixText);
    }

    [DataObjectMethod(DataObjectMethodType.Select, false)]
    public DataSet1.tbl_clientsDataTable getClients(string prefixText, int count)
    {
        return Adapter.GetDataByTopNBusinessName(count, prefixText);
    }
}

 One of the most important parts is making sure the web service is correctly decorated with [System.Web.Script.Services.ScriptService] .  Nothing happened without that(not that I could see) until I used Nikhil’s Web Development Helper  http://projects.nikhilk.net/Projects/WebDevHelper.aspx .  I saw a 500 Internal Server Error telling the script can’t run without ScriptService.  Never knew about that great tool until I came across another post while trying to find out my issue.

 The webservice
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Text;



/// 
///
 Summary description for WebService
/// 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetClients(string prefixText, int count)
    {
        List<string> clients = new List<string>();
        clientsBLL c = new clientsBLL();
        DataSet1.tbl_clientsDataTable dt = c.getClients(prefixText, count);
        StringBuilder sb = new StringBuilder();
        foreach (DataSet1.tbl_clientsRow dr in dt.Rows)
        {
            clients.Add(dr.businessName);
            
        }

        return clients.ToArray();




    }

}

The relevant aspx page code



        <asp:TextBox ID="myTextBox" runat="server">asp:TextBox><br />
        <br />
        <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
         TargetControlID="myTextBox"
         ServiceMethod="GetClients"
         ServicePath="~/WebService.asmx"
         MinimumPrefixLength="2"
         CompletionInterval="1000"
         EnableCaching="true"
         CompletionSetCount="20"
         CompletionListCssClass="autocomplete_completionListElement"
         CompletionListItemCssClass="autocomplete_listItem"
         CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
         DelimiterCharacters=";, :">
        cc1:AutoCompleteExtender>