Ajax Autocompleteextender没有显示autocompletelist可供选择

时间:2010-04-23 06:05:30

标签: c# asp.net autocompleteextender

我正在使用asp.net和c#.net中的文本框工作ajax auto completeextender。我无法获得可供选择的列表,我有适当的Web服务方法,名为..can任何人都可以指导我完成automo完成。

<form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
    <asp:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="TextBox1"
    ServiceMethod="GetCompletionList"
    ServicePath="AutoComplete.asmx"
    MinimumPrefixLength="0" 
    CompletionInterval="50"
    EnableCaching="true"
    CompletionSetCount="1"    
    DelimiterCharacters=";, :"
    ShowOnlyCurrentWordInCompletionListItem="true">        
</asp:AutoCompleteExtender>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>

并且Web服务方法包含以下代码

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [ScriptService]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class AutoComplete : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string[] GetCompletionList(string prefixText, int count)
        {
            List<string> responses = new List<string>();

            for (int i = 0; i < count; i++)

                responses.Add(prefixText + (char)(i + 65));
            return responses.ToArray();
        }
    }

1 个答案:

答案 0 :(得分:1)

您的方法需要有以下两个attirubutes

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]