So I have spent 4 days now researching and trying everything I can find on StackOverflow and other sites. And I just can't get my Ajax AutoCompleteExtender to work. I am using VS 2012 and ASP.NET and C# building for .NET 4.5 Here is my code:
~/Dashboard/Default.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolKit" %>
<ajaxToolKit:ToolkitScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Dashboard/AutoComplete2.asmx" />
</Services>
</ajaxToolKit:ToolkitScriptManager>
<asp:TextBox ID="CarMake_TextBox" runat="server"></asp:TextBox>
<ajaxToolKit:AutoCompleteExtender
ID="CarMake_AutoCompleteExtender" runat="server"
Enabled="true"
ServicePath="AutoComplete2.asmx"
ServiceMethod="GetCarMakeList"
TargetControlID="CarMake_TextBox"
MinimumPrefixLength="1" FirstRowSelected="True"
>
</ajaxToolKit:AutoCompleteExtender>
</asp:Content>
~/Dashboard/AutoComplete2.asmx.cs (C#)
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace CDC.Dashboard
{
/// <summary>
/// Summary description for AutoComplete2
/// </summary>
[WebService(Namespace = "http://websiteleaders.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete2 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCarMakeList(string prefixText, int count)
{
string sql = "Select DISTINCT Make from Car_Makes_Models Where Make LIKE @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "Data Source=localhost\\SQLEXPRESS;Initial Catalog=CDC;Integrated Security=True");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["Make"].ToString(), i);
i++;
}
return items;
}
}
}
I cannot for the life of me get it to work. When I try running the Web Service through a web browser and entering in values, it retrieves the required info just right and returns them as an array of strings. But it just seems like the AutoCompleteExtender is just not firing.
It is worth noting that the first time I tried it, it worked. Then after any subsequent tries it didn't. I am dumbstruck. And if I run it with IE I get the know error message about using the AJAX ScriptManager (Which I already am using) and 4.0 Scripts. I have the AJAX toolkit properly installed and referenced and yes it does support .NET v4.5 which is my Target Framework.