自动建议在asp.net中使用Ajax控件

本文关键字:Ajax 控件 net asp | 更新日期: 2023-09-27 18:05:32

我试图在TextBox中做自动建议,我使用Ajax控件这样做。我给movies array赋值。我想给该值从数据库通过过滤用户表的电子邮件Id,用户用来登录到网站。我无法将Label值调用到下面的方法中。在页面加载期间,我已经将用户的电子邮件id存储在标签中。帮我做这件事。

[System.Web.Services.WebMethodAttribute(),System.Web.UI.WebControls, System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
   // Create array of movies
    string[] movies = {"Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II"};
    // Return matching movies
    return (from m in movies where m.StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}

自动建议在asp.net中使用Ajax控件

如果您正在使用AJAX控件工具包,您可以在这里看到示例。

我不确定标签是什么,但您需要设置UseContextKey=true;并指定ajaxToolkit:AutoCompleteExtender的上下文键

在您的示例中,您可以将以下代码添加到Page。负载:

if(!Page.IsPostBack)
{
  AutoCompleteExtenderID.ContextKey = LabeWtihEmal.Text;
}

这是因为web方法是静态的。在加载页面时,将AutoCompleteExtender的上下文键设置为标签值(电子邮件id)。另外,确保UseContextKey设置为true。