简单的asp.net autocompleteExtender无法正常工作

时间:2016-09-15 03:13:43

标签: asp.net ajax autocomplete

我目前在使用ajax autoCompleteExtender时遇到了一些问题。

.Aspx文件

  <asp:toolkitscriptmanager runat="server" ID ="scropt" EnablePageMethods ="true" EnablePartialRendering ="true">
        </asp:toolkitscriptmanager>


        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:AutoCompleteExtender ID="AutoCompleteExtender1" MinimumPrefixLength="2" TargetControlID ="TextBox1" 
            ServiceMethod="GetCompletionList" runat="server"  CompletionInterval ="100"></asp:AutoCompleteExtender>

.Aspx.cs文件

 [System.Web.Script.Services.ScriptMethod]
        [System.Web.Services.WebMethod]
        public static string[] GetCompletionList(string prefixText, int count)
        {

            System.Diagnostics.Debug.WriteLine("prefix:" + prefixText);
            List<string> list = new List<string>();

            list.Add("hello");
            list.Add("world");
            list.Add("everyone");

            return list.ToArray();
        }

此代码的预期行为是,在文本框中输入2个字母时,文本框下拉列表中会返回字符串值列表。然而,这并没有发生。我使用fiddler来跟踪我的http请求,并意识到文本框没有向服务器发送任何http请求。有谁知道这个的原因或我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

@weejing我运行你的代码它是完美的工作。 如果有任何混淆,你复制我的代码。

aspx代码

 <body>
        <form id="form1" runat="server">
        <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </cc1:ToolkitScriptManager>
         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" MinimumPrefixLength="1" TargetControlID ="TextBox1" 
                ServiceMethod="GetCompletionList" runat="server" CompletionInterval ="100">
    </cc1:AutoCompleteExtender>
        </form>
    </body>

aspx.cs代码

[System.Web.Script.Services.ScriptMethod]
        [System.Web.Services.WebMethod]
        public static string[] GetCompletionList(string prefixText, int count)
        {

            System.Diagnostics.Debug.WriteLine("prefix:" + prefixText);
            List<string> list = new List<string>();

            list.Add("hello");
            list.Add("world");
            list.Add("everyone");

            return list.ToArray();
        }