C# 在asp.net中使用Ajax控件工具包并将值传递给数组的AutoSuggest

C# 在asp.net中使用Ajax控件工具包并将值传递给数组的AutoSuggest,c#,asp.net,ajaxcontroltoolkit,C#,Asp.net,Ajaxcontroltoolkit,这是页面加载 protected void Page_Load(object sender, EventArgs e) { if (Session["useremail"] == null) Response.Redirect("Home.aspx"); else { Label8.Text = Session["useremail"].ToString(); }

这是页面加载

protected void Page_Load(object sender, EventArgs e)
    {
        if
            (Session["useremail"] == null) Response.Redirect("Home.aspx");
        else
        {
            Label8.Text = Session["useremail"].ToString();
        }
        if (!Page.IsPostBack)
        {
            TextBox1_AutoCompleteExtender.ContextKey = Label8.Text;
        }
    }
现在,我已将会话用户电子邮件存储在TextBox1_AutoCompleteExtender.ContextKey中

如何使用以下方法将TextBox1_AutoCompleteXtender.ContextKey值传递给变量

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {

        string[] movies = { "Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II" };


        return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
    }

我不想传递预定义的数组值,而是想传递数据库表中的一列user column name is firstname,我只能用email id值过滤它。请帮助

您可以通过在包含GetCompletionList的web服务中启用会话状态来解决此问题。。。方法,以便您可以使用与ASP.NET Web应用程序/站点中相同的方式访问用户的电子邮件地址

默认情况下,关闭web方法的会话支持。必须通过将WebMethod属性的EnableSession属性设置为true,为每个web方法显式启用它。启用后,您可以使用ASP.NET中习惯的方式访问会话状态

例如:

[WebMethod(EnableSession = true), ScriptMethod()]
public static string[] GetCompletionList(string prefixText, int count, string 
    contextKey)
{ 
   var useremail = Session["useremail"] ?? null;
   //...
}
有关WebMethodAttribute的EnableSession属性的更多信息,请参见:

请注意,如果web服务的客户端使用者使用cookie来维护会话状态,则它们必须支持HTTP cookie。对于我认为是您的主要客户机的现代浏览器来说应该没有问题

有关在web服务中使用ASP.NET会话的详细信息?只需转到MSDN上的以下链接:


我收到此错误->非静态字段、方法或属性'System.Web.UI.Page.Session.Get'需要对象引用。您是否可以复制/粘贴引发此错误的代码行,以及该行调用的上下文的更多信息。受保护的无效页面\u Loadobject sender,EventArgs e{if Session[useremail]==null Response.RedirectHome.aspx;else{Label8.Text=Session[useremail].ToString;}if!Page.IsPostBack{TextBox1_AutoCompleteExtender.ContextKey=Label8.Text;}[WebMethodEnableSession=true,ScriptMethod]公共静态字符串[]GetCompletionListstring prefixText,int count,string contextKey{var useremail=Session[useremail].ToString;}我很困惑。您能发布一些代码来说明如何调用GetCompletionList方法吗?