【问题标题】:ASP.Net AJAX Autocomplete Not WorkingASP.Net AJAX 自动完成不工作
【发布时间】:2010-11-01 15:52:50
【问题描述】:

我查看了this link 并尝试了那里的所有建议,但我的 Asp.Net AJAX 自动完成功能仍然无法正常工作。

我有一个只有标签、文本框和自动完成器的测试项目:

<asp:ToolkitScriptManager ID="ScriptManager" runat="server">
</asp:ToolkitScriptManager>
<asp:Label ID="FieldLabel" Text="Label:" runat="server"></asp:Label>
<asp:TextBox ID="InputField" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender 
    ID="Autocompleter" 
    TargetControlID="InputField" 
    ServiceMethod="GetCompletionList" 
    ServicePath="~/TestWebService.asmx" 
    MinimumPrefixLength="1" 
    CompletionInterval="1000" 
    runat="server">
</asp:AutoCompleteExtender>

我在 aspx 页面上没有任何代码隐藏。在 TestWebService.asmx.cs 中,我有:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompetionList(string prefixText, int count)
{
    string[] results = { "test", "test", "test" };
    return results;
} 

理论上,我的文本框应该有一个自动完成下拉菜单,其中包含 3 个单词“test”的实例。在实践中,我可以在文本框中输入任何我想要的内容,但什么也没有发生。有谁知道我做错了什么?

【问题讨论】:

  • 我尝试过的相同代码但对我不起作用。任何其他设置都需要更改。

标签: asp.net ajax asp.net-ajax


【解决方案1】:

看起来您的 Web 服务方法缺少参数。还要确保您为自动完成“下拉”设置了正确的样式。换句话说,将您的代码与the reference 进行比较。

【讨论】:

  • 真正的问题是我不会拼写。请参阅下面的答案。
【解决方案2】:

我想通了。我拼错了 WebMethod 的名称。如果您注意到,它是“GetCompletionList”,而不是“GetCompletionList”。

现在一切正常。

【讨论】:

    【解决方案3】:

    你应该使用

    代码中 Public 之后的单词(静态)

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    
    public static string[] GetCompetionList(string prefixText, int count)
    
    {
      string[] results = { "test", "test", "test" };
    
    
       return results;
    
    } 
    

    【讨论】:

      【解决方案4】:

      我遇到了类似的问题,通过删除 web.config 文件中的这些行来解决。

      <rules>
              <rule name="san aspx">
                <!--Removes the .aspx extension for all pages.-->
                <match url="(.*)"/>
                <conditions logicalGrouping="MatchAll">
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" />     
                </conditions>
                <action type="Rewrite" url="{R:1}.aspx"/>
              </rule>
            </rules>
      

      【讨论】:

        猜你喜欢
        • 2012-01-25
        • 1970-01-01
        • 2013-11-06
        • 2017-05-18
        • 2015-05-06
        • 2013-10-28
        • 1970-01-01
        • 1970-01-01
        • 2017-02-27
        相关资源
        最近更新 更多