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; }
}
}
精彩评论