AjaxControlToolKit autocompleteextender not rendering

Go To StackoverFlow.com

0

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

2012-04-04 07:40
by Priyank Patel
is it working for u - Pranay Rana 2012-04-04 07:58
I tried the code what you posted , now it says error creating control autocomplete1 'true' could not be set on property 'caching - Priyank Patel 2012-04-04 08:02
i suggest you to download code of that article and than try to include in your project or check for the error by comparing your code . - Pranay Rana 2012-04-04 08:04
I'm not sure whether you are using AutocompleteSearchByName.asmx. If so, there is must be something wrong with that. can you show your code for AutocompleteSearchByName.asmx - Ashwini Verma 2012-04-04 09:01
@AshwiniVerma , I edited my questio - Priyank Patel 2012-04-04 09:11
@freebird: are you using ScriptManager? Try to use ToolkitScriptManager instead of ScriptManager - Ashwini Verma 2012-04-04 09:16
@AshwiniVerma , I am using ToolkitScriptManager,do you think .asmx file has any issues - Priyank Patel 2012-04-04 09:17
can't say right now but it seems there is file path issue. make sure () AutoCompleteSearchByName.asmx file is in the same folder with the aspx file - Ashwini Verma 2012-04-04 09:25


1

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

2012-04-04 07:49
by Pranay Rana
Ads