So I'm trying to implement the AutoCompleteExtender tool from the AJAX Control Toolkit.
The following is the implementation of the AutoCompleteExtender on my ASPX page:
<asp:TextBox runat="server" ID="CustomerTextBox" CssClass="form-control" /><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 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 theGetAllCustomerNames method. Could someone please help me find where I'm going wrong?
Additional info:
- I'm using Visual Studio 2013.
- This is a ASP.NET Web Form application running on .NET 4.5.
- I used the default style and template as when a new project is created and so a Master Page is being used.
- The ToolkitScriptManager is specified in the Master File and I have setEnablePageMethods property to true.
Thanks in advance!