Control name: autocompleteextender
Function: enables dynamic prompts and automatic filling when entering text boxes.
Example: Enter the prompt content in the text box during Google search,
Ajax implementation:
If you are using Visual Studio 2005 and have not installed aspajaxextender, install it first: Click here to download
Download the ajaxcontroltoolkit. You can download the DLL file here: Click here to download it.
Method 1:
Add all controls in ajaxcontroltoolkit (. dll) to the toolbar of vs2005 or vs2008:
Add to toolbar:
Right-click the toolbar tab: Add tab> Name> Option> browse> select dll File> OK
Add the following content to the webpage:Code:
<Div>
< ASP : Scriptmanager ID = "SM" Runat =" Server ">
</ ASP: scriptmanager >
< ASP: updatepanel ID = "Updatepanel1" Runat = "Server" autopostback = "true">
< Contenttemplate >
< ASP: textbox ID = "TB" Runat = "Server" Text = ""> </ ASP: textbox >
< Ajax: autocompleteextender ID = "Googlesa" Runat = "Server" Servicepath = "Autocomplete. asmx"
Targetcontrolid = "TB" Servicemethod =" Getcompletionlist ">
</ Ajax: autocompleteextender >
</ Contenttemplate >
</ ASP: updatepanel >
</ Div >
Attribute introduction:
1. targetcontrolid: ID of the control that will be automatically input by the secondary node. The control can only be textbox;
2. servicepath: indicates the path of the web service that provides the service. If this parameter is not specified, servicemethod indicates the method name on the page;
3. servicemethod: indicates the method name for providing the service;
4. minimumprefixlength: specifies the minimum number of characters that the Textbox Control should have when the prompt service is provided. The default value is 3;
5. completionsetcount: Number of displayed items. The default value is 10;
6. enablecaching: whether to cache data on the client. The default value is true;
7. completioninterval: the time interval for reading data from the server. The default value is 1000. Unit: milliseconds.
Note:
1. the WebService must be declared as [system. Web. Script. Service. scriptservice]
In this way, AJAX can be called at the front end.
2. Three conditions for the method: strictly abide!
The return type must be string [];The parameter type must be string or Int;
Parameter Name: prefixtext, Count.
WebService code:
[System. Web. Script. Services. scriptservice]
Publicclass AutoComplete: system. Web. Services. WebService
{
[Webmethod]
Publicstring [] Getcompletionlist ( String Prefixtext, Int Count)
{
If (COUNT = 0 )
Count = 10 ;
If (Prefixtext. Equals ( "Xyx" ))
Return New String [ 0 ];
List < String > Items = New List < String > (Count );
Random random1 = New Random ();
For ( Int I = 0 ; I <count; I ++)
{
Char C1 = ( Char ) Random1.next ( 65 , 97 );
Char C2 = ( Char ) Random1.next ( 97 , 122 );
Char C3 = ( Char ) Random1.next ( 97 , 122 );
Items. Add (prefixtext + C1 + C2 + C3 );
}
Return Items. toarray ();
}
}
Prefixtext: indicates the input content. It can be used to search databases and query strings starting with it. Return the queried string in string [] format.