The autocompleteextender control is used to populate the textbox with prompts. Like Google suggest. Here is a small example.
Example: Enter characters in the text box. Some optional lists are randomly displayed in the text box.
1) Create an ASP. NET Ajax-enabled web project. Name it autocompleteextender1.
2) Add the following in the source on the default. aspx page:Code:
1 < Div >
2 < C0: autocompleteextender ID = "Autocompleteextender1" Targetcontrolid = "Textbox1" Completionsetcount = "12"
3 Servicepath = "Autocomplete. asmx" Servicemethod = "Getcompletionlist" Completioninterval = "1000" Enablecaching = "True" Minimumprefixlength = "2" Runat = "Server" >
4 </ C0: autocompleteextender >
5
6 </ Div >
7 < ASP: textbox ID = "Textbox1" Runat = "Server" > </ ASP: textbox >
3) Add a web service named autocomplete. asmx to the project and add the following code:
1 [System. Web. Script. Services. scriptservice ()]
2 Public Class AutoComplete: system. Web. Services. WebService
3 {
4
5 [Webmethod]
6 Public String [] Getcompletionlist ( String Prefixtext, Int Count)
7 {
8 If (Count = 0 )
9 {
10Count= 10;
11}
12
13 If (Prefixtext. Equals ( " Xyx " ))
14 {
15Return New String[0];
16}
17
18 List < String > Items = New List < String > (Count );
19 Random random1 = New Random ();
20 For ( Int I = 0 ; I < Count; I ++ )
21 {
22 Char C1 = ( Char ) Random1.next ( 65 , 97 );
23 Char C2 = ( Char ) Random1.next ( 97 , 122 );
24 Char C3 = ( Char ) Random1.next ( 97 , 122 );
25 Items. Add (prefixtext + C1 + C2 + C3 );
26 }
27 Return Items. toarray ();
28 }
29 }
4) Save and press Ctrl + F5 to preview in the browser. The effect is as follows: