簡體   English   中英

asp.net 中的 AutoSuggest 使用 Ajax 控制工具包並將值傳遞給數組

[英]AutoSuggest in a asp.net using Ajax controls toolkit and passing values to array

這是頁面加載

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

現在我已將 session 用戶郵件存儲在 TextBox1_AutoCompleteExtender.ContextKey 中。

如何使用將 TextBox1_AutoCompleteExtender.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();
    }

我不想傳遞預定義的數組值,而是從數據庫表用戶(列名是名字)傳遞一列,我只能使用 email id 值對其進行過濾。 請幫忙

You can solve this by enabling session state in your web service which contains the GetCompletionList(...) method so that you can access the user's email address in the same fashion as in your ASP.NET Web application / site.

默認情況下,web 方法的 session 支持已關閉。 您必須通過將 WebMethod 特性的 EnableSession 屬性設置為 true,為每個 web 方法顯式啟用它。 啟用后,您可以按照在 ASP.NET 中習慣的相同方式訪問 session state。

例如:

[WebMethod(EnableSession = true), ScriptMethod()]
public static string[] GetCompletionList(string prefixText, int count, string 
    contextKey)
{ 
   var useremail = Session["useremail"] ?? null;
   //...
}

有關 WebMethodAttribute 的 EnableSession 屬性的更多信息,請參見此處:

http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx

Be aware that if the clients (consumers) of your web service use cookies to maintain the session state, that they must support HTTP cookies. 對於現代瀏覽器(我認為是您的主要客戶)應該沒問題。

需要更多關於在 web 服務中使用 ASP.NET Session 的信息? 只需 go 到 MSDN 上的以下鏈接:

http://msdn.microsoft.com/en-us/library/aa480509.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM