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.