[英]Why is the AutoCompleteExtender firing the Page_Load event instead of the service method?
So I'm trying to implement the AutoCompleteExtender tool from the AJAX Control Toolkit. 因此,我正在尝试从AJAX控制工具包中实现AutoCompleteExtender工具。
The following is the implementation of the AutoCompleteExtender on my ASPX page: 以下是我的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>
This is the service method implemented in the code behind file: 这是在文件后面的代码中实现的服务方法:
[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();
}
The problem I'm facing is that whenever I type a character into the text box the Page_Load event fires instead of the GetAllCustomerNames method. 我面临的问题是,每当我在文本框中键入字符时,就会触发Page_Load事件而不是GetAllCustomerNames方法。 Could someone please help me find where I'm going wrong? 有人可以帮我找到我要去的地方吗?
Additional info: 附加信息:
Try [System.Web.Services.WebMethod] not WebMethod() and remove the next line. 尝试使用[System.Web.Services.WebMethod]而不是WebMethod()并删除下一行。
You set AutoPostBack="true"
on the TextBox, just delete AutoPostBack or set it to false
. 您在TextBox上设置AutoPostBack="true"
,只需删除AutoPostBack或将其设置为false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.