In this article I will explain with an example, how to use AJAX AutoCompleteExtender Control with Web Page without using Web Service in ASP.Net using C# and VB.Net.
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
Using the ASP.Net AJAX Control Toolkit
First you have to download and install the AJAX Control Toolkit DLL. For more details, refer my article Install AJAX Control Toolkit in Visual Studio ToolBox.
Registering ASP.Net AJAX Control Toolkit
In order to use ASP.Net AJAX Control Toolkit controls, you will need to add reference of AJAX Control Toolkit Library and then register on the Page as shown below.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
HTML Markup
The HTML Markup consists of an ASP.Net ScriptManager control, ASP.Net TextBox and an ASP.Net AJAX AutoCompleteExtender control.
The AJAX Control Toolkit AutoCompleteExtender has been set with ServiceMethod property and the TargetControlID has been set with the Id of the TextBox control.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="SearchCustomers"
    MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
    TargetControlID="txtContactsSearch" FirstRowSelected="false">
You will need to import the following namespaces.
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Services
Server Side Method
The following Web Method is used to populate the records from the Customers Table of the Northwind database.
This method accepts two parameters namely:
1. prefixText (string)
2. count (int)
Note: It is very important that you keep the signature of the method i.e. the name of the parameters are same as given, otherwise the method won’t work with AutoCompleteExtender.
The value of the ContactName field is inserted into a Generic List collection of string and then returned to the ASP.Net AJAX AutoCompleteExtender Control.
public static List<string> SearchCustomers(string prefixText, int count)
    using (SqlConnection conn = new SqlConnection())
        conn.ConnectionString = ConfigurationManagerConnectionStrings["constr"].ConnectionString;
        using (SqlCommand cmd = new SqlCommand())
            cmd.CommandText = "select ContactName from Customers where ContactName like @SearchText + '%'";
            cmd.Parameters.AddWithValue("@SearchText", prefixText);
            cmd.Connection = conn;
            List<string> customers = new List<string>();
            using (SqlDataReader sdr = cmd.ExecuteReader())
                while (sdr.Read())
            return customers;
Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
    Using conn As SqlConnection = New SqlConnection()
        conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
        Using cmd As SqlCommand = New SqlCommand()
            cmd.CommandText = "select ContactName from Customers where ContactName like @SearchText + '%'"
            cmd.Parameters.AddWithValue("@SearchText", prefixText)
            cmd.Connection = conn
            Dim customers As List(Of String) = New List(Of String)()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                While sdr.Read()
                End While
            End Using
            Return customers
        End Using
    End Using
End Function
ASP.Net AJAX AutoCompleteExtender without using WebServices
Download Code