AutoComplete Demonstration

Type some characters in this textbox. The web service returns random words that start with the text you have typed.

AutoComplete 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 words that begin with the prefix typed into the textbox.


The dropdown with candidate words supplied by a web service is positioned on the bottom left of the text box.


In the sample above, the textbox is associated with an AutoCompleteExtender that pulls words that start with the contents of the textbox using a web service.


When you have typed more content than the specified minimum word length, a popup will show words or phrases starting with that value. Caching is turned on, so typing the same prefix multiple times results in only one call to the web service.

AutoComplete Properties

The textbox is linked with an AutoCompleteExtender which is initialized with this code. The italic properties are optional:

<ajaxToolkit:AutoCompleteExtender 
    runat="server" 
    ID="autoComplete1" 
    TargetControlID="myTextBox"
    ServiceMethod="GetCompletionList"
    ServicePath="AutoComplete.asmx" 
    MinimumPrefixLength="2" 
    CompletionInterval="1000"
    EnableCaching="true"
    CompletionSetCount="12" />
  • 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:
    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count) { ... }
    Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
  • 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.
  • CompletionInterval - Time in milliseconds when the timer will kick in to get suggestions using the web service.
  • EnableCaching - Whether client side caching is enabled.
  • CompletionSetCount - Number of suggestions to be retrieved from the web service.
Copyright © 2006-2007 Microsoft Corporation. All Rights Reserved.