Previous Article: Atlas Series 1 (simple experience)
Original
When I was doing Asp.net, some forms were of reference type, such as entering the province and city of the city or entering the employee name. In the past, there were two extremes, one is that the user
Input in Textbox, and select in dropdownlist. First, you need to remember all the input content, and the input efficiency is high. Second, you do not need to know the input content in advance,
However, when too many records are provided for selection, it is also troublesome to choose. A smart choice is a compromise. We used to set the dictionary reference and then select it in the dictionary. Now we have
Atlas makes implementation much easier. The autocompleteproperties of Atlas can meet this requirement. It can be set through
Targetcontrolid is used to control a control, and a web services path and Web Services method must be provided.
The attributes of autocompleteproperties include:
Attribute name |
Attribute description |
Remarks |
Targetcontrolid |
ID of the control to be controlled |
Generally, it is the textbox ID. |
Servicepath |
Process the Web Services path in the intelligently selected list |
|
Servicemethod |
Network Service that processes the smart selection list |
This method generally contains two parameters (string prefixtext, int count) |
Enabled |
Available or not |
|
Minimumprefixlength |
Minimum prefix length |
Intelligent selection is provided when the input length is minimum. |
The following is a demo:
According to the previous articleArticleIntroduction: Create an Atlas website and add the following content to the page:Code:
1 < Div >
2 < ASP: Panel ID = "Panel1" Runat = "Server" Height = "125px" Width = "125px" >
3 </ ASP: Panel >
4 < ASP: textbox ID = "Textbox1" Runat = "Server" > </ ASP: textbox > < ASP: dropdownlist ID = "Dropdownlist2"
5 Runat = "Server" >
6 </ ASP: dropdownlist >
7 < Atlas: autocompleteextender ID = "Autocompleteexetender1" Runat = "Server" Dropdownpanelid = "Panel1" >
8 < Atlas: autocompleteproperties Targetcontrolid = "Textbox1" Enabled = "True" Servicepath = "WebService. asmx" Servicemethod = "Getwordlist" Minimumprefixlength = "1" />
9 </ Atlas: autocompleteextender >
10 </ Div >
The following is a network service that handles intelligent selection: 1 Using System;
2 Using System. Web;
3 Using System. collections;
4 Using System. Web. Services;
5 Using System. Web. Services. Protocols;
6 Using System. IO;
7
8
9 /**/ /// <Summary>
10///Summary of WebService
11/// </Summary>
12 [WebService (namespace = " Http://tempuri.org/ " )]
13 [Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
14 Public Class WebService: system. Web. Services. WebService {
15
16 Public WebService () {
17
18//If you use the designed components, uncomment the following lines:
19//Initializecomponent ();
20}
21 Public String [] Autocompletewordlist = Null ;
22 [Webmethod]
23 Public String [] Getwordlist ( String Prefixtext, Int Count)
24 {
25 If (Autocompletewordlist = Null )
26 {
27 String [] Templist = File. readalllines (server. mappath ( " ~ /App_data/words.txt " ), System. Text. encoding. Default );
28 Array. Sort (templist, New Caseinsensitivecomparer ());
29 Autocompletewordlist = Templist;
30 }
31 Int Index = Array. binarysearch (autocompletewordlist, prefixtext, New Caseinsensitivecomparer ());
32 If (Index < 0 )
33 {
34Index= ~Index;
35}
36 Int Matchedcount = 0 ;
37 For (Matchedcount = 0 ; Matchedcount < Count && Matchedcount + Index < Autocompletewordlist. length; matchedcount ++ )
38 {
39 If ( ! Autocompletewordlist [matchedcount + Index]. startswith (prefixtext, stringcomparison. currentcultureignorecase ))
40 {
41Break;
42}
43 }
44 String [] Returnvalue = New String [Matchedcount];
45 If (Matchedcount > 0 )
46 {
47Array. Copy (autocompletewordlist, index, returnvalue,0, Matchedcount );
48}
49 Return Returnvalue;
50 }
51
52 }
53
54
If the TXT file in app_datais wors.txt.
The running effect is as follows:
This
Controls are easy to use, but I think they should not be abused. For example, when many people enter forms concurrently, each few words can call the Web
Services, the items retrieved each time will not be too large. For network services, the connection takes too much time, which seriously deviates from the principle of designing a large block of network services. Therefore, the application should also look at the lower ring
Environment.
Previous Article: Atlas Series 1 (simple experience)