Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Create and Access Session Variables

How to Create and Access Session Variables

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ASPnoob
    wrote on last edited by
    #1

    Hi all I am trying learn how to create and access session variables inside and out side of pageload. I've found that I can create a session variable inside of the pageload method like the following:

    int myID = 0;
    Session["UserID"] = RetrievedID;

    Then I can access the session variable in the pageload method of another page like the following:

    int myID = (int)Session["UserID"];

    Some questions I have are do I need to use Response.Redirect() method to successfully send session variables to another page, and how do I create and access session variables outside of the pageload method. Thanks in advance.

    S J N 3 Replies Last reply
    0
    • A ASPnoob

      Hi all I am trying learn how to create and access session variables inside and out side of pageload. I've found that I can create a session variable inside of the pageload method like the following:

      int myID = 0;
      Session["UserID"] = RetrievedID;

      Then I can access the session variable in the pageload method of another page like the following:

      int myID = (int)Session["UserID"];

      Some questions I have are do I need to use Response.Redirect() method to successfully send session variables to another page, and how do I create and access session variables outside of the pageload method. Thanks in advance.

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      ASPnoob wrote:

      do I need to use Response.Redirect() method to successfully send session variables to another page

      No

      ASPnoob wrote:

      how do I create and access session variables outside of the pageload method.

      similarly as you did now. Now, overall, you need to understand the concept of Session. First and foremost, it is not page level, it is across the application per user level. For a given user, a session can be created in any page and accessed in any page. Read about it in much more detail, here: MSDN: ASP.NET Session State Overview[^] Exploring Session in ASP.NET[^]

      Sandeep Mewara Microsoft ASP.NET MVP [My latest Article]: Server side Delimiters in ASP.NET[^]

      1 Reply Last reply
      0
      • A ASPnoob

        Hi all I am trying learn how to create and access session variables inside and out side of pageload. I've found that I can create a session variable inside of the pageload method like the following:

        int myID = 0;
        Session["UserID"] = RetrievedID;

        Then I can access the session variable in the pageload method of another page like the following:

        int myID = (int)Session["UserID"];

        Some questions I have are do I need to use Response.Redirect() method to successfully send session variables to another page, and how do I create and access session variables outside of the pageload method. Thanks in advance.

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        Session variables are stored on the web server, and are available to that pacticular sessionID number for every page.

        G 1 Reply Last reply
        0
        • A ASPnoob

          Hi all I am trying learn how to create and access session variables inside and out side of pageload. I've found that I can create a session variable inside of the pageload method like the following:

          int myID = 0;
          Session["UserID"] = RetrievedID;

          Then I can access the session variable in the pageload method of another page like the following:

          int myID = (int)Session["UserID"];

          Some questions I have are do I need to use Response.Redirect() method to successfully send session variables to another page, and how do I create and access session variables outside of the pageload method. Thanks in advance.

          N Offline
          N Offline
          niranjan479
          wrote on last edited by
          #4

          No.U dnt need to use it.Because sessions willbe created in web server so whenever you want to access it from any page you can simply access it by using session["sessionid"] collection object....Thank you!

          1 Reply Last reply
          0
          • J jkirkerx

            Session variables are stored on the web server, and are available to that pacticular sessionID number for every page.

            G Offline
            G Offline
            gopal pradhan
            wrote on last edited by
            #5

            to store into session: Session["someID"]="Text To Store"; to retrive : string someString=Session["someID"].ToString(); :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups