Export (0) Print
Expand All

How to: Use the ContextSensitiveAutoCompleteExtender Control

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This topic describes how to use the ContextSensitiveAutoCompleteExtender control. Developers can use the ContextSensitiveAutoCompleteExtender control to provide AutoComplete behavior that filters suggested values based on the values in multiple controls on a Web page. For more information about this control, see ContextSensitiveAutoCompleteExtender Control.


To use the ContextSensitiveAutoCompleteExtender, you must have a Web site or Web application project that meets the following conditions:

  • It has been configured to target Microsoft .NET Framework 3.5.
  • It has a reference to the ASP.NET AJAX Control Toolkit 3.5 on the Web site (or in the Web application project).


The following procedure describes how to use the ContextSensitiveAutoCompleteExtender control in an application. Remember that the client code does not handle any exceptions that the Web service throws. It is up to the clients to implement their own client-side exception handling.

To use the extender

  1. Add a reference to the AjaxControlToolkit.WCSFExtensions.dll assembly.
  2. Implement a Web service that returns the list of suggested values. The signature of the method must match the following code.
    public string[] GetCompletionList(string prefixText, int count, Dictionary<string, string> contextValues)

    You can replace "GetCompletionList" with a name of your choice, but the return type and parameter names and types must match exactly, including case.

    Note: The user sees the suggested list of values only after the Web service completes. You should consider the performance of the Web service and its impact on the user experience.

  3. Add the ContextSensitiveAutoCompleteExtender control to the Web page that has the TextBox control that is the target of the AutoComplete behavior. The following code is an example and is taken from the AutoComplete QuickStart.
    <%@ Register Assembly="AjaxControlToolkit.WCSFExtensions" Namespace="AjaxControlToolkit.WCSFExtensions" TagPrefix="ajaxtoolkitwcsfextensions" %>
    <ajaxtoolkitwcsfextensions:CompletionContextItem Key="State" ControlId="StateDropDown" />
    <ajaxtoolkitwcsfextensions:CompletionContextItem Key="City" ControlId="CityTextBox" />

 The following list describes the attributes of the ContextSensitiveAutoCompleteExtender control:

  • TargetControlID. This is the TextBox control where the user types the content to be automatically completed.
  • CompletionSetCount. This is the number of suggestions to be retrieved from the Web service.
  • CompletionInterval. This is the time in milliseconds when the timer will start to get suggestions using the Web service.
  • MinimumPrefixLength. This is the minimum number of characters that must be entered before getting suggestions from the Web service.
  • ServiceMethod. This is the Web service method that is called to retrieve the list of suggested values.
  • ServicePath. This is the path to the Web service that the extender will use to retrieve the list of suggestions.
  • CompletionContextItems. This is the collection of controls that supply context information.
  • CompletionContextItem. This contains a control identifier and an associated key name that is used to send context information to the Web service.
    Note: The controls that you specify must have an attribute named value. This means you can use controls such as a TextBox control or a DropDownList control as the controls that supply context information, but you cannot use a RadioButton control.

© 2014 Microsoft