Hi,
I'm having trouble getting the Ajax Toolkit autocomplete extender to work. I have the web service set up as its own file in the same project and calling that alone works - the correct list of results is output as xml.
But when entering text into the textbox nothing happens. I don't know if the web service isn't been called or whether the response isn't being displayed.

Any help would be appreciated. Here's my code:

The web page:

<form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
        <Services>
            <asp:ServiceReference Path="AutoComplete.asmx" />
        </Services>
    </asp:ScriptManager>
    <div>
        <asp:TextBox ID="tbProduct" runat="server" autocomplete="off" />
        <ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server" TargetControlID="tbProduct" ServicePath="AutoComplete.asmx" ServiceMethod="getProducts" EnableCaching="true" />
    </div>
    </form>

The ASMX (which works fine on its own)

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]


public class AutoComplete : System.Web.Services.WebService
{

    [WebMethod]

    public string[] getProducts(string prefixText)
    {

        DataSet dtst = new DataSet();
        string connStr = ConfigurationManager.ConnectionStrings["mySQLserver"].ConnectionString;
        MySqlConnection sqlCon = new MySqlConnection(connStr);

        string strSql = "SELECT name FROM products WHERE name LIKE '" + prefixText + "%' ";
        MySqlCommand sqlComd = new MySqlCommand(strSql, sqlCon);

        sqlCon.Open();
        MySqlDataAdapter sqlAdpt = new MySqlDataAdapter();
        sqlAdpt.SelectCommand = sqlComd;
        sqlAdpt.Fill(dtst);

        string[] cntName = new string[dtst.Tables[0].Rows.Count];
        int i = 0;

        try
        {
            foreach (DataRow rdr in dtst.Tables[0].Rows)
            {
                cntName.SetValue(rdr["name"].ToString(), i);
                i++;
            }
        }
        catch { }

        finally
        {
            sqlCon.Close();
        }

        return cntName;

    }

}

Some examples I've looked at include autocomplete="off" in the textbox control but it seems to make no difference if its there or not.

Can anyone help?

Thanks,
Hericles

Update: I discovered the ajaxToolkit script manager and tried that but nothing changed...

I take that back - it now works with the ajaxToolkit:ToolkitScriptManager in place of the standard ScriptManager. Problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.