[英]Why is the AutoCompleteExtender firing the Page_Load event instead of the service method?
因此,我正在尝试从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方法。 有人可以帮我找到我要去的地方吗?
附加信息:
尝试使用[System.Web.Services.WebMethod]而不是WebMethod()并删除下一行。
您在TextBox上设置AutoPostBack="true"
,只需删除AutoPostBack或将其设置为false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.