I've tried to the letter to search for mistakes in my code, but i can't myself get that autocomplete extender to work. Help wanted.
Here's my code: (excerpt from my aspx page)
<asp:TextBox ID="TextBox1" Width="120px" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" ServicePath="SearchAutoComplete.asmx" MinimumPrefixLength="1">
</cc1:AutoCompleteExtender>
My Webservice code:
[WebMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
List<string> returnData = new List<string>();
MySqlConnection con = new MySqlConnection(Connection.ConnectionString());
string sql = "select title from blog where title like '%" + prefixText + "%'";
MySqlCommand cmd = new MySqlCommand(sql, con);
con.Open();
MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
returnData.Add(reader["title"].ToString());
}
return returnData.ToArray();
}
Add reference to your web service in ScriptManager like this
refer link below for more info
Ajax AutoComplete textbox in gridview
First of all, you remove "static" from your web method declaration. Second is add EnableCaching="true" CompletionSetCount="20" in your
code block. Hope this will solve your problem.
When you create a Webservice, at the top there is a line that say:
Just uncomment the line:
This happened to me in Visual Studio 2010.
As well as the
GetCompletionList
method being incorrectly declared asstatic
, it needs to have two attributes;[System.Web.Services.WebMethod]
and[System.Web.Script.Services.ScriptMethod]
So your declaration should look like this:
Also your service class should have the following attributes:
The autocomplete extender will also appear to be broken if your
GetCompletionList
method throws an exception. To guard against this you should add atry..catch
block around the code the functionI think your problem is that the
GetCompletionList
method is declaredstatic
.If you run up just the .asmx code in a debugger session (or browse to the .asmx file if you have deployed your code to a webserver) you should see a list of available operations for the web-service. When I change the code in the Ajax control toolkit examples to declare this method as static the operation is no longer in the list and the autocomplete extender also stops working.
Change your method signature to:
How to troubleshoot this:
Comment out your SQL code. Just return an array with some test data. Does that work? Do you see it? If not, your webservice code is not getting called. If that works, your problem is with your database code.... Is your webservice code on the calling page?