Databases Reference
In-Depth Information
control toolkit to suggest a list of well-known regions to users based on the countries they
enter.
<asp:TextBox ID=”textBox” runat=”server” Text=”<%# FieldValueEditString %>”/>
<ajax:AutoCompleteExtender ID=”autoCompleteExtender” runat=”server”
TargetControlID=”textBox” ServicePath=”/RegionCompletionService.svc”
ServiceMethod=”GetCompletionList” />
The AutoCompleteExtender requires a web service method to get the list of suggested values.
This web service, shown in Listing 10.13, defines a single method, GetCompletionList , that
will be called by the client-side JavaScript code generated by the AutoCompleteExtender
based on the ServicePath and ServiceMethod attributes. Although the method name itself
is configured in markup, the names and the order of the parameters have to match exactly
what the AutoCompleteExtender implementation expects. In particular, the prefixText
parameter receives the current value user entered in the Region text box, the count speci-
fies the number of matching items that should be returned, and the contextKey will be
the value user entered in the Country field.
LISTING 10.13 RegionCompletionService Implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
namespace WebApplication
{
[ServiceContract]
public class RegionCompletionService
{
private static readonly Dictionary<string, string[]> regionsByCountry =
new Dictionary<string, string[]>(StringComparer.InvariantCultureIgnoreCase)
{
{ “Canada”,
new[] {
“ON”, “QC”, “NS”, “NB”, “MB”, “BC”, “PE”, “SK”, “AB”, “NL”,
“NT”, “UT”, “NU”
}
},
{ “USA”,
new[] {
“AL”, “AK”, “AZ”, “AR”, “CA”, “CO”, “CT”, “DE”, “FL”, “GA”,
“HI”, “ID”, “IL”, “IN”, “IA”, “KS”, “KY”, “LA”, “ME”, “MD”,
“MA”, “MI”, “MN”, “MS”, “MO”, “MT”, “NE”, “NV”, “NH”, “NJ”,
Search WWH ::




Custom Search