摘要:ASP.NET For AutoComplete By Page Method
1: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
2:
3: <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControlToolkit" %>
4:
5: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6:
7: <html xmlns="http://www.w3.org/1999/xhtml" >
8: <head runat="server">
9: <title>VIN Test</title>
10: </head>
11: <body>
12: <form id="form1" runat="server">
13: <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
14: </asp:ScriptManager>
15: VIN#: <asp:TextBox ID="txtVIN" runat="server"></asp:TextBox>
16: <AjaxControlToolkit:AutoCompleteExtender ID="aceVIN" runat="server" ServiceMethod="GetVINList" TargetControlID="txtVIN" CompletionInterval="100" MinimumPrefixLength="1">
17: </AjaxControlToolkit:AutoCompleteExtender>
18: </form>
19: </body>
20: </html>
[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
5: using System.Web.UI;
6: using System.Web.UI.WebControls;
7: using System.Web.Services;
8: using System.Web.Script.Services;
9:
10: namespace WebApplication1
11: {
12: public partial class WebForm1 : System.Web.UI.Page
13: {
14: protected void Page_Load(object sender, EventArgs e) {}
15:
16: [WebMethod]
17: [System.Web.Script.Services.ScriptMethod()]
18: public static String[] GetVINList(String prefixText, Int32 count)
19: {
20: Int32 iCount = 10;
22: for (int intI = 0; intI < iCount; intI++)
21: String[] strContent=new String[iCount];
23: {
24: strContent[intI] = prefixText + intI.ToString();
25: }
26: return strContent;
27: }
28: }
29: }