---
title: "Ajax Toolkit AutoCompleteExtender Control in Asp.Net"  
description: "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 wo"  
author: "Amit Singh"  
published: 2010-12-06  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/256/ajax-toolkit-autocompleteextender-control-in-asp-dot-net  
category: "ajax"  
tags: ["ajax"]  
reading_time: 2 minutes  

---

# Ajax Toolkit AutoCompleteExtender Control in Asp.Net

[AutoComplete](https://answers.mindstick.com/qa/95214/why-does-the-autocomplete-in-microsoft-outlook-always-break) is an ASP.NET AJAX extender that can be attached to any [TextBox control](https://www.mindstick.com/articles/320/textbox-control-in-vb-dot-net), and will associate that control with a [popup panel](https://www.mindstick.com/blog/445/simple-popup-panel-in-html) to display words that begin with the prefix typed into the textbox.\

**AutoComplete [Properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule):**

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

•**ServiceMethod** - The [web service](https://www.mindstick.com/articles/45/web-services-in-asp-dot-net) method to be called. The [signature](https://www.mindstick.com/interview/516/explain-about-xml-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](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-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](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) named contextKey of type string (as described above).

## Code:

**Step1**: we use the register [directives](https://www.mindstick.com/blog/44/directives-in-asp-dot-net) for [Ajax control toolkit](https://www.mindstick.com/articles/138/ajax-control-toolkit-confirmbuttonextender) 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"></cc1:AutoCompleteExtender>
```

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

And this method will return maching name.

**Default.aspx.cs**

```
[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();         }
```

**Output:**

![AjaxControl Toolkit AutoCompleteExtender Control in Asp.Net](https://www.mindstick.com/mindstickarticle/a7e242ef-fd21-4d4a-8cc6-ccbf4972be65/images/b3ce19cf-7754-48ae-8016-3799f54518de.png)

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

![AjaxControl Toolkit AutoCompleteExtender Control in Asp.Net](https://www.mindstick.com/mindstickarticle/a7e242ef-fd21-4d4a-8cc6-ccbf4972be65/images/5b4490f8-ed53-4f07-97dd-7bf30987a5e5.png)

---

Original Source: https://www.mindstick.com/articles/256/ajax-toolkit-autocompleteextender-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
