Autocompleteextender的Web服务无法正常工作

时间:2012-02-21 13:38:57

标签: c# asp.net asp.net-mvc web-services asp.net-ajax

我使用ajax auto extender代码就像

 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
    <asp:TextBox ID="txt_AutoComplete" runat="server" Width="200"></asp:TextBox>
    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" 
    ServiceMethod="GetNames" ServicePath="~/AutoComplete.asmx" TargetControlID="txt_AutoComplete"> </asp:AutoCompleteExtender>

和Web服务在Autocomplete.asmx中,Web服务未调用

[WebMethod]

        public string[] GetNames(string prefixText, int count)
        {
            ArrayList sampleList = new ArrayList();

            sampleList.Add("ABC"); sampleList.Add("Hello");

            sampleList.Add("Hi");

            sampleList.Add("Hey");

            ArrayList filteredList = new ArrayList();
            foreach (string s in sampleList)
            {

                if (s.ToLower().StartsWith(prefixText.ToLower()))

                    filteredList.Add(s);

            }
            return (string[])filteredList.ToArray(typeof(string));

        }

但是ajax auto extender无效

1 个答案:

答案 0 :(得分:0)

你必须使用以上所需方法

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]