Use of AutoCompleteExtender in AjaxControlToolKit

Source: Internet
Author: User

1. After installing ASPAJAXExtSetup. msi, create a new VS2005 project. You can select an AJAX template or not.
2. If you do not select an AJAX template to create a website project, add the following code to the configuration file:
<System. web>
<HttpHandlers>
<Remove verb = "*" path = "*. asmx"/>
<Add verb = "*" path = "*. asmx "validate =" false "type =" System. web. script. services. scriptHandlerFactory, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "/>
<Add verb = "*" path = "* _ AppService. axd "validate =" false "type =" System. web. script. services. scriptHandlerFactory, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "/>
<Add verb = "GET, HEAD" path = "ScriptResource. axd "type =" System. web. handlers. scriptResourceHandler, System. web. extensions, Version = 1.0.61025.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 "validate =" false "/>
</HttpHandlers>
</System. web>
Add a reference to AjaxControlToolKit. dll and add the control to the toolbox.
3. Drag the AjaxControlToolKit. ToolKitScriptManager control to the page...
4. Drag TextBox (the text control that you will implement automatic search) to the page with ID = "myTextBox "...
5. Drag the AjaxControlToolKit. AutoCompleteExtender control to the page with ID = "autoComplete1"
6. Set the TargetControlID attribute of autoComplete1 to "myTextBox"... to control myTextBox...
7. Create a New webservice. asmx named "AutoComplete. asmx". The Code is as follows:

// (C) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

Using System;
Using System. Collections. Generic;
Using System. Web. Services;

[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]

[System. Web. Script. Services. ScriptService]

Public class AutoComplete: WebService
{
Public AutoComplete ()
{
}

[WebMethod]
Public string [] GetCompletionList (string prefixText, int count)
{
If (count = 0)
{
Count = 10;
}

If (prefixText. Equals ("xyz "))
{
Return new string [0];
}

Random random = new Random ();
List <string> items = new List <string> (count );
For (int I = 0; I <count; I ++)
{
Char c1 = (char) random. Next (65, 90 );
Char c2 = (char) random. Next (97,122 );
Char c3 = (char) random. Next (97,122 );

Items. Add (prefixText + c1 + c2 + c3 );
}

Return items. ToArray ();
}
}
8. At last, you must specify several important attributes of the AutoCompleteExtender control:
MinimumPrefixLength: Specifies the length of the text to start searching for judgment.
ServicePath: Specify the webservice file path created above
ServiceMethod: Specify the defined webMethod.

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.