AutoCompleteExtender不调用ServiceMethod

问题描述:

包括AutoCompleteExtender不调用ServiceMethod

<%@ 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时,我没有看到任何错误或警告。感谢您的任何建议

+0

您是否尝试在浏览器中直接调用您的服务方法?类似于“MyPage.aspx/SearchOnboardingMembers”。 或者将它放在一个单独的.asmx文件中,并尝试打开'MyService.asmx',检查它的方法,在浏览器中调用它,然后检查浏览器调试网络选项卡以确保您使用正确的路径调用它。 –

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

不知何故,ASP.NET不会从不同的页面调用相同的WebMethod。最初我将Web方法从一个页面复制/粘贴到另一个页面的代码后面;第二页功能从未在UI上调用,如我在这里的问题所述。

我把这个WebMethod移动到了一个基页类,它在两页都有效!它可能与后面两个页面代码中使用的名称相同,但它并没有提前工作。