This project is read-only.
AutoComplete Behavior | AutoComplete QuickStart | Patterns related to autocomplete

ContextSensitiveAutoCompleteExtender

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.

Note:
The AjaxControlToolkit AutoComplete extender includes the ContextKey property. With this property, it is possible to pass context information from the Web page to the Web service. The service can use this context information to filter the list of suggested values. If you want to specify the contents of another control on the page (for example, the contents of a text box), you must write JavaScript to populate the ContextKey property with the value of that control. With the ContextSensitiveAutoCompleteExtender, it is easy to specify multiple controls on a Web page that participate in providing context information for the list of suggested values. You do this in the declaration of the ContextSensitiveAutoCompleteExtender control on the page, and you do not have to write client-side JavaScript.

The ContextSensitiveAutoCompleteExtender derives from the AjaxControlToolkit AutoComplete extender. This means it provides the same functionality as the AjaxControlToolkit AutoComplete extenders, such as the completion list, the ability to attach to a target control, and more. To the base extender, it adds the ability to specify different controls that contribute context.

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).

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.

AutoComplete Behavior | AutoComplete QuickStart | Patterns related to autocomplete

Last edited Nov 20, 2007 at 2:33 PM by ejadib, version 5

Comments

ZakKra Jan 22, 2009 at 12:49 PM 
Is there a way of using these extenders with a newer version of Ajax Toolkit?
I am getting this error when I try adding controls to my tool bar:

There was an error loading types from assembly 'C:\Program Files\Microsoft Web Client Software Factory February 2008\Microsoft Practices Library with EntLib 4.0\AjaxControlToolkit.WCSFExtensions.dll'

'Could not load file or assembly 'AjaxControlToolkit, Version=3.0.11119.25533, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. The system cannot find the file specified.'

Thanks
Zak

boldicu Sep 16, 2008 at 3:52 PM 
Hi,
How can I use ServerSideValidation (ajaxtoolkitwcsfextensions:ServerSideValidationExtender) with the last version of AjaxControlToolkit (3.0.20820.18235).
Now i get a runtime error "Could not load file or assembly 'AjaxControlToolkit, Version=3.0.11119.25533, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
"

Thank you,
Flaviu Boldea