Author: dflying Chen (http://dflying.cnblogs.com /)
For more information, see ASP. NET Atlas AutoComplete behavior or AutoComplete extender)
Let's test the above two methods through an instance:
First, let's create a dictionary to provide an automatically completed list. This dictionaryCopyFromAtlasFor example. Net. Save itWorddata.txtAnd placeApp_dataDirectory.
Word List
Access Control List (ACL)
Ado. net
Aggregate event
Alpha Channel
Anchoring
Antialiasing
Application Base
Application domain (appdomain)
Application manifest
Application State
ASP. NET
ASP. NET application services database
ASP. NET mobile controls
ASP. NET mobile Web Forms
ASP. NET page
ASP. NET Server Control
ASP. NET web application
Assembly
Assembly Cache
Assembly manifest
Assembly metadata
Assertion (assert)
Association class
Associators
Asynchronous Method
Attribute
Authentication
Authorization
Autopostback
Bounds
Boxing
C #
Card
Catalog
CCW
Chevron
Chrome
Chtml
CIM
CIM Object Manager
CIM schema
Class
Client Area
Client coordinates
Clip
Closed generic type
CLR
CLS
CLS-compliant
Code access security
Code-behind class
Code-behind File
Code-behind page
Com callable wrapper (CCW)
Com InterOP
Common Information Model (CIM)
Common Language Runtime
Common Language Runtime host
Common Language Specification (CLS)
Common Object File Format (coff)
Common Type System (CTS)
Comparison Evaluator
Composite Control
Configuration File
Connection
Connection Point
Constraint
Constructed generic type
Constructed type
Consumer
Container
Container Control
Content Page
Context
Context Property
Contract
Control State
Cross-page posting
CTS
Custom attribute (attribute)
Custom Control
Then createWeb ServiceIt is used to provide a list of suggestions. The logic is not much to talk about. It is probably to read the dictionary above and find the relevant vocabulary based on the input. Pay attention to it.GetwordlistMethod signature.
Suggestion Web Service Code
Using System;
Using System. IO;
Using System. Web;
Using System. collections;
Using System. Collections. Generic;
Using System. Threading;
Using System. Web. Services;
Using System. Web. Services. Protocols;
Using System. xml. serialization;
[WebService (namespace = " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
Public Class Autocompleteservice: system. Web. Services. WebService
{
Private Static String [] Autocompletewordlist = Null ;
[Webmethod]
Public String [] getwordlist ( String Prefixtext, Int Count)
{
// Init the suggest list
If (Autocompletewordlist = Null )
{
String [] Temp = File. readalllines (server. mappath ( " ~ /App_data/worddata.txt " ));
Array. Sort (temp, New Caseinsensitivecomparer ()); // Sort for Binary Search
Autocompletewordlist = Temp;
}
Int Index = Array. binarysearch (autocompletewordlist, prefixtext, New Caseinsensitivecomparer ());
If (Index < 0 )
{
Index= ~Index;
}
Int Matchingcount;
For (Matchingcount = 0 ; Matchingcount < Count && Index + Matchingcount < Autocompletewordlist. length; matchingcount ++ )
{
If(!Autocompletewordlist [Index+Matchingcount]. startswith (prefixtext, stringcomparison. currentcultureignorecase ))
Break;
}
String [] returnvalue = New String [Matchingcount];
If (Matchingcount > 0 )
{
Array. Copy (autocompletewordlist, index, returnvalue,0, Matchingcount );
}
Return Returnvalue;
}
}
Web ServiceAfter the establishment, you can test it directly. If everything is correct, we will continue to writeAtlasPage.
First, regardless of the ClientAutoComplete BehaviorOr on the server sideAutoComplete Extender, OneScriptmanagerAre essential:
< Atlas: scriptmanager Runat = "Server" ID = "Scriptmanager" />
If you use a clientAutoComplete BehaviorFirst, you need to writeHTML input:
< Input ID = "Clienttextbox" Type = "Text" Style = "Width: 400px ;" />
Then, the corresponding writingAtlas script. Please be careful when writing. After all, this is basically not powerful.IDE.
< Page Xmlns: script = "Http://schemas.microsoft.com/xml-script/2005" >
< Components >
< Textbox ID = "Clienttextbox" >
< Behaviors >
< AutoComplete
Serviceurl = "Autocompleteservice. asmx"
Servicemethod = "Getwordlist"
Minimumprefixlength = "2"
Completionsetcount = "10"
Completioninterval = "500" />
</ Behaviors >
</ Textbox >
</ Components >
</ Page >
On the server sideAutoComplete ExtenderEverything is very simple, we only need to add a serverTextboxAnd oneAutoComplete ExtenderYou can:
< ASP: textbox ID = "Servertextbox" Runat = "Server" Width = "400px" />
< Atlas: autocompleteextender ID = "Servercompleteextender" Runat = "Server" >
< Atlas: autocompleteproperties Enabled = "True" Minimumprefixlength = "2" Targetcontrolid = "Servertextbox"
Servicemethod = "Getwordlist" Servicepath = "Autocompleteservice. asmx" />
</ Atlas: autocompleteextender >
So far, we have achieved success. Let's test it in the browser:
ClientAutoComplete Behavior:
ServerAutoComplete Extender:
This instanceProgramOfSource codeDownload here: http://files.cnblogs.com/dflying/AutoCompleteDemo.zip