Search code examples
c#asp.netajaxautocompleteajaxcontroltoolkit

AutoCompleteExtender is not invoking ServiceMethod


Include

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

My ASPX code

<asp:TextBox ID="txtSearchKey" runat="server" Width="200" AutoPostBack="true" OnTextChanged="txtSearchKey_TextChanged" />
<asp:TextBoxWatermarkExtender ID="weSearchKey" runat="server" Enabled="True" TargetControlID="txtSearchKey" WatermarkText="Enter search criteria" WatermarkCssClass="watermark" />
<asp:AutoCompleteExtender ServiceMethod="SearchOnboardingMembers" MinimumPrefixLength="3" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtSearchKey" ID="onboardingSearchExtender" runat="server" FirstRowSelected="false" OnClientItemSelected="GetSelectedId" CompletionListCssClass="completionList" CompletionListItemCssClass="listItem"                                CompletionListHighlightedItemCssClass="itemHighlighted" CompletionListElementID="divCompletionListElement" />

My backend code

[ScriptMethod()]
[WebMethod]
public static List<string> SearchOnboardingMembers(string prefixText, int count)
    {
        var filteredSearchText = String.Join(",", prefixText.Split(' ').Where(x => x.Length > 2));

       //my code 

        return items;
    }

This code is working fine on a page and I needed the same function on a different page. I just copy pasted HTML and Backend code into the new ASPX file. But, strangely it is not working on that page. When I mean not working, the WebMethod is not getting invoked on this page. Do we have any way to debug the issue here? I don't see any error or warning anywhere when I type in the text box but it is not invoking WebMethod. Thanks for any suggestions


Solution

  • I don't know why but here is the solution I got.

    Somehow, ASP.NET doesn't invoke the same WebMethod from a different page. Initially I copy / pasted the Web method from one page to another page's code behind; the second page function was never invoked on UI as stated in my problem here.

    I moved this WebMethod to a base page class and it worked in both pages!! It might be the same name used in both page's code behind, it didn't work earlier.