locked
AutoCompleteExtender not firing RRS feed

Answers

All replies

  • User-1787668906 posted

    And let me clarify something... the way I understand it each time you type a character the web service should be called after CompletionInterval milliseconds, correct?  The user doesn't need to click anything, press enter, etc. right?

    Wednesday, September 18, 2013 3:28 PM
  • User-1360095595 posted

    Right.

    Now perhaps you can post your relevant code so we don't have to play magicians.

    Wednesday, September 18, 2013 3:34 PM
  • User-1787668906 posted

    Yes, I realize you need code, but I figured the fact that even the official demo of the control didn't work was relevant.

    In any event here it is...

    <asp:ScriptManager runat="server" ID="smScriptManager" />
            
            <asp:TextBox runat="server" ID="txtAutoComplete" Width="300" autocomplete="off" />
            <ajaxToolkit:AutoCompleteExtender runat="server" TargetControlID="txtAutoComplete" 
                ServiceMethod="GetCompletionList" ServicePath="autocomplete.asmx"
                MinimumPrefixLength="1" CompletionInterval="100" />
    [WebService(Namespace = "http://tempuri.org/")]
        [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 autocomplete : System.Web.Services.WebService
        {
            [System.Web.Services.WebMethod]
            [System.Web.Script.Services.ScriptMethod]
            public string[] GetCompletionList(string prefixText, int count)
            {
                SqlConnection sqlConn = new SqlConnection(@"Server=.\SQLEXPRESS;Database=PBP;Trusted_Connection=True;");
                List<string> results = new List<string>();
    
                sqlConn.Open();
                
                using(sqlConn)
                {                
                    SqlCommand sqlCmd = new SqlCommand(@"SELECT TOP " + count.ToString() + " IndustryName FROM [PBP].[lkp].[Industry] WHERE IndustryName LIKE '%" + prefixText + @"%' ORDER BY IndustryName", sqlConn);
    
                    SqlDataReader dr = sqlCmd.ExecuteReader();
    
                    if(dr.HasRows)
                    {
                        while(dr.Read())
                        {
                            results.Add(dr[0].ToString());
                        }
                    }
                }
    
                return results.ToArray();
            }
        }




    Wednesday, September 18, 2013 3:37 PM
  • User-1787668906 posted

    I have also downloaded the source and run this excellent walkthrough, but I still get no drop down list of values in either browser.

    http://aspdotnet-suresh.blogspot.com/2011/03/how-to-implement-auto-complete-textbox.html

    Wednesday, September 18, 2013 4:16 PM
  • User-1360095595 posted

    Your code looks Ok to me. Put a breakpoint in the webmethod and see if it triggers and also if it returns anything (if results has has elements in it).

    Edit: Corrected mistyped word.

    Wednesday, September 18, 2013 5:15 PM
  • User-1787668906 posted
    The breakpoint is never hit through the test aspx page but it's got off I test the asmx on the browser directly.
    Wednesday, September 18, 2013 5:54 PM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 22, 2013 10:50 PM