Is AutoComplete Extender working

There are numerous blogs and forums discussing that “AutoComplete Extender is not working”. When I had to work on it for one of my clients, I too found that AutoComplete Extender does not work. I followed the steps given in but I was left with the same impression that “AutoComplete Extender is not working” . Anyway try try again till you get gain is the formula I generally adopt. After googling of hours together, I found the solution. Though the solution is given in many forums/blogs, yet you need to give more attention to it to catch the point. So in this blog I tried to highlight the small but the important lines that require more attention. AutoComplete Extender AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox. Following are the steps:- Step 1 : Add autocomplete extender where you want to and configure it as explained in
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:TextBox ID="txtSuggest" runat="server" ></asp:TextBox>
   <ajaxToolkit:AutoCompleteExtender runat="server"


Step 2 : Add the following web service with name "WebService.asmx"and consume it :-
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;

/// Summary description for WebService
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SuggestionService : System.Web.Services.WebService

    public string[] GetSuggestions(string prefixText, int count)
        int i = 0;
        DataView data = GetData();
        data = FilterData(data, prefixText);
        string[] suggestions = new string[data.Count];

        foreach (DataRowView row in data)
            suggestions[i++] = row["FirstName"].ToString();

        return suggestions;

    private DataView GetData()
        DataView view = (DataView)HttpContext.Current.Cache["Suggestions"];
        if (view == null)
            SqlDataAdapter adapter = new SqlDataAdapter(
            "SELECT * FROM addressbook", System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"]
            DataTable table = new DataTable();
            view = table.DefaultView;

            // Store the entire data set to the ASP.NET Cache for
            // further reuse
            HttpContext.Current.Cache["Suggestions"] = view;

        return view;

    private DataView FilterData(DataView view, string prefix)
        // Filter out undesired strings
        view.RowFilter = String.Format("FirstName LIKE '{0}%'", prefix);
        return view;


No comments:

Post a Comment