我正在使用AutoCompleteExtender
来自 AjaxControlToolkit 的TextBox
.
简而言之,当我将工具拖放AutoCompleteExtender
到我的 TextBox 上,然后单击“添加自动完成页面方法”时,我收到以下错误:
无法创建页面方法“GetCompletionlist,因为没有找到 CodeBehind 或 CodeFile!
谷歌搜索错误后,我基本上创建了自己的 Web 服务,称为 AutoCompelte.asmx。下面是该类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace AutoCompleteTest
{
/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://microsoft.com/webservices/")]
[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 AutoComplete : System.Web.Services.WebService
{
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
// Create array of movies
string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };
// Return matching movies
return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
}
}
当然,以上是虚拟数据……稍后,我将从数据库中获取数据。
我的 Default.aspx 看起来像这样:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
From
<asp:TextBox ID="txtFrom" runat="server">
</asp:TextBox>
<asp:AutoCompleteExtender runat="server"
ID="txtFrom_AutoCompleteExtender"
TargetControlID="txtFrom"
ServiceMethod="GetCompletionList"
ServicePath="AutoComplete.asmx"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>
当我运行网站......并在文本框中输入时,没有任何反应。没有显示扩展器。即使我输入“星”。
我错过了什么,为什么我一开始就收到这个错误?
PS我在我的大学电脑上,所以我认为这个错误可能是由于我使用的网络类型。没有把握。
任何帮助都非常感谢!
谢谢。