【问题标题】:autocomplete textbox .NET doesn't work自动完成文本框 .NET 不起作用
【发布时间】:2013-08-05 09:39:03
【问题描述】:

我的 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;
}

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

【问题讨论】:

标签: asp.net


【解决方案1】:
[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# 代码上使用同名函数:)

【讨论】:

  • 抱歉改进了[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; } 仍然不起作用
【解决方案2】:

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

  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.

【讨论】:

  • Did 也不起作用,但我不明白这一点:“您的控件同一页面上的服务代码”是我的控件在 nationality.aspx 上,并且在国籍 aspx.cs 上有代码不同的页面?
  • 我的意思是你的服务代码在代码端,控制在同一页面的设计端,那么你不需要指定服务路径。它会自动调用它。
  • 好的。现在删除此 [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] 并添加 [System.Web.Services.WebMethod(true)]。检查更新的代码。可能现在可以工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-12
  • 1970-01-01
  • 2019-07-13
相关资源
最近更新 更多