static List<string> keywordList = new List<string>();
protected void btnEnter_Click(object sender, EventArgs e)
{
lbxKeywords.Items.Add(tbxKeyword.Text);
keywordList.Add(tbxKeyword.Text);
tbxKeyword.Text = string.Empty;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
Session["keywords"] = keywordList;
keywordList.Clear();
Response.Redirect("Results.aspx");
}
When I clear the list session become null. why is that?
thanx..
That’s because what you store in the session variable is just a reference to the list, not a copy of the list.
Create a copy of the list for the session variable: