我的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;
}
我正在尝试自动完成功能。 我做错了什么?
答案 0 :(得分: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#代码上使用samename函数:)
答案 1 :(得分: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.