How to: Use the ContextSensitiveAutoCompleteExtender Control
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 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
- Add a reference to the AjaxControlToolkit.WCSFExtensions.dll assembly.
- Implement a Web service that returns the list of suggested values. The signature of the method must match the following code.
[System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] 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: 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.
- 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:ContextSensitiveAutoCompleteExtender ID="PostalCodeAutoComplete" runat="server" TargetControlID="PostalCodeTextBox" CompletionSetCount="30" CompletionInterval="400" MinimumPrefixLength="1" ServiceMethod="GetZipCodes" ServicePath="PostalCodeAutoCompleteService.asmx"> <CompletionContextItems> <ajaxtoolkitwcsfextensions:CompletionContextItem Key="State" ControlId="StateDropDown" /> <ajaxtoolkitwcsfextensions:CompletionContextItem Key="City" ControlId="CityTextBox" /> </CompletionContextItems> </ajaxtoolkitwcsfextensions:ContextSensitiveAutoCompleteExtender>
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: 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.