locked
AJAX Autocomplete Control help... RRS feed

  • Question

  • User-507786106 posted

    I have a textbox, ajax autocomplete control- I need help configuring my my webservice to the ajax control and recieve data from textbox.

    Design Code

     <asp:TextBox ID="txtCompanyName" runat="server" CssClass="textbox"  AutoPostBack="true"
           Width="265px" Height="30px" OnTextChanged="txtCompanyName_TextChanged"></asp:TextBox>

    AJAX Control
            <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"  
                     TargetControlID="txtCompanyName"
                      ServicePath="AutoComplete.asmx"
                      ServiceMethod="GetCompletionList"
                      MinimumPrefixLength="3"
                      CompletionInterval="1000"
                       EnableCaching="true"
                       CompletionSetCount="20">
       </asp:AutoCompleteExtender>

    Source Code (code-behind)

    protected void txtCompanyName_TextChanged(object sender, EventArgs e)
    {
         How to I access the AutoComplete.asmx.cs page on TextChanged?
     }

    AutoComplete.asmx.cs Page

    [WebService(Namespace = "http://tempuri.org/", Description = "This is a Web service for *** active Customers.")]
    [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
     {
            [WebMethod]
            public string [] GetCompletionList(string strInput)
            {            
                DataTable data = new DataTable();
                CBE_Main_Class getCName = new CBE_Main_Class();  <-- initiating new class object
                           
                List<string> txtItems = new List<string>();  <-- creating array list
                string dbValues = null;

                getCName.AutoComplete(strInput);    <-- pass parameter to class object getCName
                data = getCName.DataTable;     <-- binding data Table to data DataTable

                if (!getCName.ErrorFlag)            <-- check for error
                {
                    foreach (DataRow row in data.Rows)    <-- loop through data
                    {
                        //String From DataBase(dbValues)
                        dbValues = row["COMPANY_NAME"].ToString();
                        dbValues = dbValues.ToLower();
                        txtItems.Add(dbValues);                 
                    }               
                }      
                return txtItems.ToArray();  <-- Please help me assess this array in  my autocomplete Ajax control
            }
        }

    Wednesday, October 9, 2013 3:23 PM

Answers

  • User-1360095595 posted

    Fix your webmethod:

     public string [] GetCompletionList(string prefixText, int count)

     

    Better yet, google to find some tutorials about the autocomplete so you understand why you need to make those changes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 9, 2013 3:53 PM

All replies

  • User-1360095595 posted

    You should be able to instantiate the class and call the method. That simple.

    Wednesday, October 9, 2013 3:36 PM
  • User-507786106 posted

    I am initiating a class and calling a method in my code but the AJAX control is not populating with data.  Any advice?

    Wednesday, October 9, 2013 3:48 PM
  • User-1360095595 posted

    Fix your webmethod:

     public string [] GetCompletionList(string prefixText, int count)

     

    Better yet, google to find some tutorials about the autocomplete so you understand why you need to make those changes.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 9, 2013 3:53 PM