Composite Web Application Block documentation | ObjectBuilder | ServerSideValidationExtender | ObjectContainerDataSource

ContextSensitiveAutoCompleteExtender

The ContextSensitiveAutoCompleteExtender control extends the ASP.NET AJAX Toolkit AutoComplete extender to provide additional capabilities for AutoComplete behavior. Extenders are server controls that you can use to extend a set of ASP.NET server controls by adding client-side functionality. With the ContextSensitiveAutoCompleteExtender extender, you can use values from multiple controls on the Web page to influence the list of suggestions. For example, Figure 1 illustrates a list of suggested ZIP Codes that is relevant for the current values of the city and state controls.
UsingAutoCompleteBehaviorToSuggestZIPCodes.png
Figure 1
Using AutoComplete behavior to suggest ZIP Codes.

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.

Requirements

To use the ContextSensitiveAutoCompleteExtender, you must have a Web site or Web application project that meets the following conditions:
  • It has been configured to use the ASP.NET 2.0 AJAX Extensions.
  • It has a reference to the ASP.NET AJAX Control Toolkit on the Web site (or in the Web application project).
Note:
The ContextSensitiveAutoCompleteExtender control is included in the AjaxControlToolkit.WCSFExtensions.dll assembly located in the Bin folder of this bundle. The control also ships as source code (the source code is located in the AjaxControlToolkit.WCSFExtensions folder). To build the source code, you must add the AjaxControlToolkit assembly (version 1.0.10618.0) to the Lib folder of the bundle.

Using the Control

The following procedure describes how to use the ContextSensitiveAutoCompleteExtender control in an application.

To use the extender
  • Add a reference to the AjaxControlToolkit.WCSFExtensions.dll assembly.
  • Implement a Web service that returns the completion list. 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:
The user will see the suggested list of values only after the Web service completes. You should consider the performance of the Web service and the impact on the user experience.
  • Add the ContextSensitiveAutoCompleteExtender control to the Web page that has a TextBox control that will be 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:
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 the supply context information, but you cannot use a RadioButton control.

Composite Web Application Block documentation | ObjectBuilder | ServerSideValidationExtender | ObjectContainerDataSource

Last edited Nov 19, 2007 at 8:58 PM by siacomuzzi, version 4

Comments

No comments yet.