Categories
Asp, Asp.net

Store Hashtable in Session

In this post we will learn how to store hashtable in session. By storing values in hashtable & then transfer them to a new page with session is easiest way.

ASP.NET session state lets you associate a server-side string containing state data with a particular HTTP client session.Session is defined as a series of requests issued by the same client within a certain period of time, and is managed by associating a session ID with each unique client.

Page 1 Code:

Hashtable ht = new Hashtable();
ht.Add("cids", guid.ToString());
ht.Add("phone", mobilebrand.SelectedItem.Text);
ht.Add("phonemodel", mobilemodel.SelectedItem.Text);
ht.Add("wstatus", wstatus.SelectedItem.Text);
Session["data"] = ht;

Page 2 Code:

if (Session["data"] != null)
{
                Hashtable ht = Session["data"] as Hashtable;
                cid.Value = ht["cids"].ToString();
                pbrand.Value = ht["phone"].ToString();
                pmodel.Value = ht["phonemodel"].ToString();
                wstatuss.Value = ht["wstatus"].ToString();
}