Session state is one of the popular state management techniques in ASP.NET environment. We developer people play with session storage every now and then. It’s pretty simple to manage session if you understand the basic concept. Here is the syntax to do that.
Or
- Session[index] = ”Value”;
- Let’ s a have an example: using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace WebApp
- {
- public partial class WebForm1: System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if(!IsPostBack)
- {
- HttpContext.Current.Items["Value"] = "Sourav Kayal in ITEM";
- HttpContext.Current.Session["Value"] = "Sourav Kayal in SESSION";
- Response.Write((string)(HttpContext.Current.Items["Value"]) + "<br>");
- Response.Write((string)(HttpContext.Current.Session["Value"]));
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Response.Write((string)(HttpContext.Current.Items["Value"]) + "<br>");
- Response.Write((string)(HttpContext.Current.Session["Value"]));
- }
- }
- }