You must Sign In to post a response.
  • Category: .NET

    How to use session in

    hello sir,
    i want to know that how to use session.
  • #723578

    Check these links

    Thanks & Regards,
    Mahesh Durgam

  • #723583

    Session is one the techniques to use data from one webform to another others include querystrings,cookies etc.

    Session state variables are stored on the webserver by default and are there for lifetime of a session.

    If you want to store any value eg a text box value in a session variable


    Here "name" is the key.

    If you want to retrieve value from session variable after the webform is redirected to another web form


    The lifetime of session is determined by timeout value in web.config file.You can adjust it according to your requirement.

    <Sessionstate mode="Inproc" timeout="20">


  • #723597

    Using session we can maintain state for multiple browsers.

    Session is started Automatically by for every new user. Every session is provided with session Id which is internally a COOKIE created by Session Id will travel between every request & response. A session is enabled by based on idle timeout. By default session idle timeout is 20min. which means if user doesn't request for server for 20min, then server will destroy the session. we can change this time in web.config as well as programatically using session object.

    When Application starts…..?

    Application started automatically when first user make a request

    When Session starts….?

    When new user make a request session will starts.

    When Pool starts…?

    When IIS will starts pool started.

    When pool ends…?

    When IIS will end pool ended.

    When Session ends….?

    Idel time 20 mins session will end.

    When Application ends…?

    All sessions are ended then Application end.


    Protected void btnSubmit_Click (Object sender,EventArgs e)
    { Session["User"]=txtUser.Text; Response.Redirect("online.aspx");

    Protected void Page_Load(object sender,EventArgs e){
    If(Session["User"]!=null) Lbl.Text="Hi ,"+Session["User"].ToString();

    for more information you can search in Google you got no.of results out of this..

    hope this information is helpful to you..

    Mark this post if it helps you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #723661

    Please check below example,

    protected void btnShowFile_Click(object sender, EventArgs e)

    Session["FileID"] = "1";

    In your ShowFile.aspx page

    protected void Page_Load(object sender,EventArgs e)
    if (!IsPostBack)
    if (Session["FileID"]!=null && Session["FileID"].ToString() == "1")
    //Code to display file

    Let me know if you have any doubt in this approach.

    Asheej T K

  • #723664

    Session is used to maintain values across pages. You can assign values in any page and get back in the any page.

    session["loginuser"] = "name of the user";

    //Calling like this
    Label1.Text = Session["loginuser"].ToString();

    //Remove like this

    //Remove all session values

    For more details refer my article about state management technique

    Your Hard work never fails

  • #723682

    You can use session to store the login details which you can use it for the other pages.

    To set the session. Try the following syntax.

    Session["loginname"]= "deva";

    to fetch the session value. You can try the following syntax

    string name = Session["loginname"].ToString();

    Hope it will be useful.

    Senior Software Engineer,
    Microsoft Certified Technology Specialist.

  • #723684
    [Response removed by Admin. Read forum policies.]

  • #723793
    Session Object:
    It saves the data for all pages for single user. It holds the data as object type. So while reading session we should cast it. session variables are used to store the User based unique values..and you can set the time limit to store the values in the session state variables..
    A session starts when:
    A new user requests an ASP file, and the Global.asa file includes a Session_OnStart procedure
    A value is stored in a Session variable
    A user requests an ASP file, and the Global.asa file uses the <object> tag to instantiate an object with session scope.
    Session["StockPicks"] = stockPicks;
    // When retrieving an object from session state, cast it to
    // the appropriate type.
    ArrayList stockPicks = (ArrayList)Session["StockPicks"];

    To set session value.
    Session["UserName"] = txtUserName.text;

    To retrieve session value.
    if (Session["UserName"] != null)
    string userName = Session["UserName"] as string;

  • #734763
    Session is used to store the data.Session automatically expires in 20 minutes. if you want we can increase or decrease the time limit.Here i gave how to get session value in javascript.

    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class _Default : System.Web.UI.Page

    protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    Session["Tes"] = "Test";

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

    <html xmlns="">
    <head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
    function x()
    var sessionValue = '<%= Session["Tes"] %>';
    return true;


    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" OnClientClick="return x()" runat="server" Text="Button" />

    Thanks & Regards
    Nothing is mine ,Everything is yours!!!

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.