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.

AutoComplete Properties:

TargetControlID - The TextBox control where the user types content to be automatically completed

ServiceMethod - The web service method to be called. The signature of this method must match the following:

ServicePath - The path to the web service that the extender will pull the word\sentence completions from. If this is not provided, the service method should be a page method.

MinimumPrefixLength - Minimum number of characters that must be entered before getting suggestions from the web service.

UseContextKey - Whether or not the ContextKey property should be used. This will be automatically enabled if the ContextKey property is ever set (on either the client or the server). If the context key is used, it should have the same signature with an additional parameter named contextKey of type string (as described above).


Step1: we use the register directives for Ajax control toolkit it associate with the project Default if we use any Ajax control extender.  We write these codes in default.aspx page 

 <%@  Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%-- ScriptManager control manages client script for AJAX enabled ASP.NET pages.This enables partial-page rendering and Web-service calls.You have to used this if you want to use ajax control--%>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:Label ID="Label1" runat="server" Text="Enter Name"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" ToolTip="Enter name"> </asp:TextBox>
<%--use the AutoComplete Extender control and its targetcontrolid is textbox1--%>
<cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
ServiceMethod="getlist" TargetControlID="TextBox1" UseContextKey="True" MinimumPrefixLength="1">

Here ServiceMethod is "getlist" in which list of name is generated

And this method will return maching name.


[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] getlist(string prefixText, int count, string contextKey)
   string[] Name = {"Yash", "yashu", "yuvraj", "Yusuf", "jeetu", "John"};  // string array is the collection of name
     // return matching name
         return (from s in Name where s.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select s).Take(count).ToArray();  


Ajax Toolkit AutoCompleteExtender Control in Asp.Net

When you will enter first character of name then matching name will display as a list.


Ajax Toolkit AutoCompleteExtender Control in Asp.Net

  Modified On Sep-07-2019 12:11:35 AM

Leave Comment