代码之家  ›  专栏  ›  技术社区  ›  quanticle

ASP.Net AJAX自动完成功能不起作用

  •  1
  • quanticle  · 技术社区  · 14 年前

    我已经看过了 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”实例的自动完成下拉列表。实际上,我可以在文本框中键入任何我想要的内容,但什么都不会发生。有人知道我做错了什么吗?

    4 回复  |  直到 7 年前
        1
  •  0
  •   Klaus Byskov Pedersen    14 年前

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

        2
  •  0
  •   quanticle    14 年前

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

    现在一切正常了。

        3
  •  0
  •   user2178872    11 年前

    代码中Public后面的单词(static)

    [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
  •  0
  •   KapilS    9 年前

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