1

我的 aspx 页面的一部分

<asp:TextBox runat="server" id= "TextBox1"  ></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender
                runat="server" TargetControlID="TextBox1"
                MinimumPrefixLength="0" ServiceMethod="getAutoComplete()"
                ServicePath="nationality.aspx.cs"                  
                >

</ajaxToolkit:AutoCompleteExtender>

我的 aspx.cs 代码:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] getAutoComlete(string prefixText, int count, string contextKey)
{
     string[] a = { "11", "22", "33" };
     return a;
}

我正在尝试自动完成。我究竟做错了什么?

4

2 回答 2

2
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] getAutoComplete(string prefixText, int count, string contextKey)
    {
string[] a = { "11", "22", "33" };
            return a;
    }

您没有在 aspx 页面和 C# 代码上使用同名函数:)

于 2013-08-05T09:41:33.613 回答
0

如果您的控件的同一页面上有您的服务代码,那么它将直接调用您的服务代码。

  try below,

//change asp page like this

<asp:TextBox runat="server" id= "TextBox1"  ></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender
                runat="server" TargetControlID="TextBox1"
                MinimumPrefixLength="0" ServiceMethod="getAutoComplete">
</ajaxToolkit:AutoCompleteExtender>

// change your .cs code as below

[System.Web.Services.WebMethod(true)]
public static string[] GetCompletionList(string prefixText, int count)
{
     string[] a = { "11", "22", "33" };
     return a;
}

Hope it helps.
于 2013-08-05T09:52:58.247 回答