【发布时间】:2014-04-22 09:51:14
【问题描述】:
所以我正在尝试从 AJAX 控件工具包中实现 AutoCompleteExtender 工具。
以下是我的 ASPX 页面上 AutoCompleteExtender 的实现:
<asp:TextBox runat="server" ID="CustomerTextBox" CssClass="form-control" AutoComplete="off" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="CustomerTextBox"
CssClass="text-danger" ErrorMessage="The Customer field is required." Display="None" />
<ajaxToolkit:AutoCompleteExtender ID="CustomerAutoCompleteExtender" runat="server" TargetControlID="CustomerTextBox"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"
ServiceMethod="GetAllCustomerNames">
</ajaxToolkit:AutoCompleteExtender>
这是代码隐藏文件中实现的服务方法:
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static string[] GetAllCustomerNames(string prefixText, int count)
{
List<string> allCustomerNames = new List<string>();
List<Customer> allCustomers = GetAllCustomers();
foreach (Customer customer in allCustomers)
{
if (customer.CustomerName.Contains(prefixText))
{
allCustomerNames.Add(customer.CustomerName);
}
}
return allCustomerNames.ToArray();
}
我面临的问题是,每当我在文本框中键入一个字符时,Page_Load 事件就会触发,而不是 GetAllCustomerNames 方法。有人可以帮我找出哪里出错了吗?
其他信息:
- 我使用的是 Visual Studio 2013。
- 这是一个在 .NET 4.5 上运行的 ASP.NET Web 窗体应用程序。
- 我在创建新项目时使用默认样式和模板,因此正在使用母版页。
- ToolkitScriptManager 在主文件中指定,我已将 EnablePageMethods 属性设置为 true。
【问题讨论】:
-
对于否决这个问题的人,您能解释一下原因吗?
标签: c# asp.net ajaxcontroltoolkit autocompleteextender