Search code examples
c#asp.netajaxcontroltoolkit

AjaxControlToolKit autocompleteextender not rendering


I am using Asp.Net/C#,In one of my pages I am using Ajax autocompleteextender for auto suggestions , Following is the code I am using

        <Services>
        <asp:ServiceReference Path="AutoCompleteSearchByName.asmx"  />
        </Services>
        </asp:ScriptManager> 
        <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
        <ajaxtoolkit:autocompleteextender runat="server" ID="autoComplete1" 
        TargetControlID="txtCountry" ServicePath="AutoCompleteSearchByName.asmx" 
        ServiceMethod="GetNames" MinimumPrefixLength="1" EnableCaching="true" />

However in the design mode it is giving me an error.The error says ,

Error creating control autocomplete1 , AutocompleteSearchByName.asmx could not be set on property ServicePath

Here is my AutoCompleteSearchByName.asmx code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace CwizBankApp
{
    /// <summary>
    /// Summary description for AutoCompleteSearchByName
    /// </summary>
    [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 AutoCompleteSearchByName : System.Web.Services.WebService
    {

        [WebMethod]
        public string[] GetNames(string prefixText)
        {
            DataSet dst = new DataSet();
            SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["Server=Server;Database=CwizData;Trusted_Connection=True"]);
            string strSql = "SELECT f_name FROM cust_master WHERE f_name LIKE '" + prefixText + "%' ";
            SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
            sqlCon.Open();
            SqlDataAdapter sqlAdpt = new SqlDataAdapter();
            sqlAdpt.SelectCommand = sqlComd;
            sqlAdpt.Fill(dst);
            string[] cntName = new string[dst.Tables[0].Rows.Count];
            int i = 0;
            try
            {
                foreach (DataRow rdr in dst.Tables[0].Rows)
                {
                    cntName.SetValue(rdr["f_name"].ToString(), i);
                    i++;
                }
            }
            catch { }
            finally
            {
                sqlCon.Close();
            }
            return cntName;
        }
    }
}

Can anybody suggest me how do I solve this issue. Thanks


Solution

  • Check that you are using proper DLL for this and have look to below code aslo

    IF it still not work check this article and by donlowding code check what mistake you done : AutoComplete With DataBase and AjaxControlToolkit

    Try this :

    <ajaxToolkit:ToolkitScriptManager  ID="ScriptManager1" runat="server">
    
    </ajaxToolkit:ToolkitScriptManager>
    <ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
      EnableCaching="true"
      BehaviorID="AutoCompleteEx"
      MinimumPrefixLength="2"
      TargetControlID="myTextBox"
      ServicePath="AutoComplete.asmx"
      ServiceMethod="GetCompletionList" 
      CompletionInterval="1000"  
      CompletionSetCount="20"
      CompletionListCssClass="autocomplete_completionListElement"
      CompletionListItemCssClass="autocomplete_listItem"
      CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
      DelimiterCharacters=";, :"
      ShowOnlyCurrentWordInCompletionListItem="true">
    

    or

    This not meet up with you answer but if you want you can also go for jquery soltuion here is full article for this : Cascading with jQuery AutoComplete