Ajax autocomplete extender not working

I have an auto-complete expander in the text box that shows the entries as a list from the database, but whern I click on texbox and start typing anything slurred. my html code

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" Enabled="True" TargetControlID="TextBox1" ServicePath="~/WebService.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20" DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true" > </asp:AutoCompleteExtender> 

And my web service

  using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data; using MySql.Data.MySqlClient; using System.Configuration; /// <summary> /// Summary description for WebService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // 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 WebService : System.Web.Services.WebService { public WebService () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public static List<string> GetCompletionList(string prefixText, int count) { MySqlConnection con = new MySqlConnection(ConfigurationManager.AppSettings["cn"]); if (con.State == ConnectionState.Closed) con.Open(); MySqlCommand cmd = new MySqlCommand("SELECT gotra FROM tbgotra WHERE gotra LIKE '%" + prefixText + "%'",con); List<string> k = new List<string>(); using (MySqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { k.Add(sdr["gotra"].ToString()); } } con.Close(); return k; } } 
+6
source share
4 answers

Try adding this line, I remember that I had the same problem when it worked for me locally, but not live.

 [WebMethod] [System.Web.Script.Services.ScriptMethod] <-- Add this line public static List<string> GetCompletionList(string prefixText, int count) .... 
+4
source

You should use

 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager> 

before TextBox1

0
source

try this signature for the web method: public string[] GetCompletionList(string prefixText, int count, string contextKey) I think the extender will not accept any return type other than the string []

0
source

In my case, I had to cancel the comment of this line in the ASMX file

 // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] 
0
source

Source: https://habr.com/ru/post/956846/


All Articles