开发者

get the value from one master to another

开发者 https://www.devze.com 2022-12-13 12:32 出处:网络
iam开发者_Go百科 using a dropdownlist in one master page. i want to get the dropdownlist value in session and i want to use it in another master page.

iam开发者_Go百科 using a dropdownlist in one master page. i want to get the dropdownlist value in session and i want to use it in another master page.

how to do this.


To put the selected value in the session, you can do something like this:

protected void ddlMyDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
    Session["MySelectedValue"] = ddlMyDropDown.SelectedValue;
}

This stores the selected value in the Session with the key "MySelectedValue".

When you want to read it back, you can do this:

string myValue = Session["MySelectedValue"]

It might be an idea to wrap up your access to the session in a class so it's all strongly-typed, and allows for you to add validation or other logic:

// Strongly-typed access to session data
public class MySessionData
{
    // Gets the username of the current logged in user if logged in, otherwise null.
    public string MyUsername
    {
        get { return Session["MyUsername"]; }
        set { Session["MyUsername"] = value; }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消