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

时间:2010-11-01 15:52:51

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

我看过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;
} 

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

4 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我明白了。我拼错了WebMethod的名字。如果你注意到它的“GetCompetionList”,而不是“GetCompletionList”。

现在一切正常。

答案 2 :(得分:0)

你应该使用

代码中的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;

} 

答案 3 :(得分:0)

我遇到了类似的问题,通过在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>
相关问题