我想第一次使用AJAX,我越來越無處。我已經閱讀了很多網站,並且據我所知,我的代碼是正確的,但是當我測試頁面時,我沒有收到任何結果。在C#asp.net 4.5 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中對此進行編程。
的同時實際上是你'.asmx' Web服務級別作爲您的母版頁或路徑錯誤? –
您是否查看了IIs日誌以查看您是否在不同的URL上請求Web服務? – Hogan