AutoCompleteExtender is not invoking ServiceMethod

本文关键字:ServiceMethod invoking not is AutoCompleteExtender | 更新日期: 2023-09-27 18:20:38

包括

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

我的ASPX代码

<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" />

我的后端代码

[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;
    }

这段代码在一个页面上运行良好,我需要在不同的页面上使用相同的函数。我只是将粘贴的HTML和后端代码复制到新的ASPX文件中。但是,奇怪的是,它在那个页面上不起作用。当我的意思是不工作时,WebMethod不会在此页面上被调用。我们有办法在这里调试这个问题吗?当我在文本框中键入时,我没有看到任何错误或警告,但它没有调用WebMethod。感谢您的任何建议

AutoCompleteExtender is not invoking ServiceMethod

我不知道为什么,但这是我得到的解决方案。

不知怎的,ASP.NET不会从不同的页面调用相同的WebMethod。最初,我将Web方法从一个页面复制/粘贴到另一个页面的代码后面;第二个页面函数从未像我在这里的问题中所说的那样在UI上调用过。

我把这个WebMethod移到了一个基本页面类中,它在两个页面中都有效!!它可能是在两个页面的代码隐藏中使用的相同名称,以前不起作用。