我第一次尝试使用 AJAX,但我无处可去。我已经阅读了许多网站,据我所知,我的代码是正确的,但是当我测试页面时,我没有得到任何结果。
这是我的aspx代码:
<%@ Page Title="Search" Language="C#" MasterPageFile="~/Search.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="NEReval.Search" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" EnableViewState="True">
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="True">
</ajax:ToolkitScriptManager>
<asp:TextBox ID="tbxSearch" runat="server" TabIndex="9" Style="position: absolute; left: 0px; top: 35px" Height="21px" Width="400px"></asp:TextBox>
<ajax:AutoCompleteExtender
ID="AutoCompleteExtender1"
TargetControlID="tbxSearch"
MinimumPrefixLength="1"
CompletionSetCount="10"
ServiceMethod="GetCompletionList"
ServicePath="AutoCompleteService.asmx"
runat="server" />
这是我的代码,它位于一个名为 AutoCompleteService.asmx 的文件中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace NEReval
{
/// <summary>
/// Summary description for AutoCompleteService
/// </summary>
[WebService(Namespace = "http://www.nereval.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : System.Web.Services.WebService
{
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count)
{
List<String> Return = SearchList.GetSearchList(HttpContext.Current.Session["sTown"].ToString());
return (from r in Return where r.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select r).Take(count).ToArray();
}
}
}
我已经测试过并且从未调用过GetSearchList,因此它没有调用GetCompletionList。谁能看到我做错了什么?我在 Visual Studio Express 2012 for Web 中对此进行了编程。