Ajax toolkit Control Learning Series (6) -- use autocompleteextender

Source: Internet
Author: User

I wonder if you have noticed that when you enter a letter or a Chinese character at the beginning of googel or other search engines, there will be subsequent prompts. Of course, I do not dare to rashly guess the technology used by Google, but today we can use ajax to provide you with controls for imitation. Google's search technology is really amazing. You can quickly find the desired information in the prompt information on its server.

See the results.

After entering Wo, the following three prompts are generated immediately. It can be simply imitated. In this example, create a WebService for demonstration.

    <  Div  >  
< ASP: scriptmanager ID = "SM" Runat = "Server" >
</ ASP: scriptmanager >
< ASP: updatepanel ID = "Updatepanel1" Runat = "Server" >
< 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 >

 

 
 

Attributes of the autocompleteextender control:
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.

Notes for use.
1. Attribute declaration:
[System. Web. Script. Services. scriptservice]
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.

 Code 
[System. Web. Script. Services. scriptservice ()]
Public Class AutoComplete: system. Web. Services. WebService
{

[Webmethod]
Public String [] 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 ();
}
}

 

    • ReferenceArticle: Http://blog.chinaunix.net/u1/44087/showart_367198.html
    • Reference: http://www.cnblogs.com/jailu/archive/2007/01/27/632201.aspx
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.