1 Hi Narasiman,
Sessions can be used to store even complex data for the user just like cookies. Actually, sessions will use cookies to store the data, unless you explicitly tell it not to. Sessions can be used easily in ASP.NET with the Session object.
Ex:-
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e) {
Session["Name"] = TextBox1.Text.ToString();
Session["Color"] = TextBox2.Text.ToString();
Label1.Text = "Session saved!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net session example: how to use session in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">asp.net session example</h2>
<asp:Label ID="Label1" runat="server" ForeColor="Crimson">
</asp:Label>
<br /><br />
<asp:Label ID="Label2" runat="server" Text="Name">
</asp:Label>
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
<br />
<asp:Label ID="Label3" runat="server" Text="Favorite Color">
</asp:Label>
<asp:TextBox ID="TextBox2" runat="server">
</asp:TextBox>
<br />
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="DodgerBlue"
Text="Save Into Session"
OnClick="Button1_Click"
/>
<br /><br />
<asp:HyperLink
ID="HyperLink1"
runat="server"
Text="Go for session test"
NavigateUrl="~/SessionTest.aspx">
</asp:HyperLink>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e) {
label1.Text = "Hi " + Session["Name"];
label1.Text += "!<br />Your favorite color is " + Session["Color"];
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">asp.net session example</h2>
<asp:Label
ID="label1"
runat="server"
Font-Size="Larger"
ForeColor="SeaGreen"
>
</asp:Label>
<br /><br />
<asp:HyperLink
ID="HyperLink1"
runat="server"
Text="Go session page"
NavigateUrl="~/Session.aspx">
</asp:HyperLink>
</div>
</form>
</body>
</html>
Thanks
If this post helps you mark it as answer
0 The Session is the server side mechanism and it is widely used to store the value. It can be used across the pages for the current session.
Session["Key"] = value;
The session is the key word and it has the two parts. Key and Value. The value can be assigned and accessed using the session key. The value will be stored as object. It has to be type casted.
Session["UserDataSet"] = dsUsers;
when you retrieve and assign back to the dataset then
DataSet dsUsersData = (DataSet) Session["UserDataSet"];
The session mode can be set to the application level or machine level.
The configuration file allows you to set the mode of session saving.
The SessionState configuration tag is available in the web.config.
The Session state can be InProc, StateServer, SqlServer.
when you say InProc then it will be stored in the processor memory. Typically you can say it will be stored on asp.net_wp.exe.
The stateserver will be stored on the memory but it can be remote and multiple application can share same.
The sqlserver state mode will maintain the state of the session. The framework has the scripts which allows you to set up this mode.
0 hi,
to store in session variable use,
Session["LastName"] = "Trivedi";
to retrive
string lastname = convert.tostring(Session["LastName"])
hope this help.
please refer
http://msdn.microsoft.com/en-us/library/ms972429.aspx
this articel has initial information about session.
hope this help.