Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 760421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:42:56+00:00 2026-05-14T15:42:56+00:00

I set a session object at one juncture in my code: Session(my_name) = Dave

  • 0

I set a session object at one juncture in my code:

Session("my_name") = "Dave"

Later in my code I give the user a chance to update this object:

Session("my_name") = TextBox1.Text

I reload my page and display a little hello statement like this:

Label1.Text = "Hello" & CStr(Session("my_name"))

The result is: “Hello Dave” no matter what I change Session(“my_name”) too.

EDIT: Here is the a full code-behind I wrote up to demonstrated:

Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1)
    If Page.IsPostBack = False Then
        Session("my_name") = "Dave"
    End If
    Label1.Text = CStr(Session("my_name"))
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    Session("my_name") = TextBox1.Text
End Sub

End Class

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:42:56+00:00Added an answer on May 14, 2026 at 3:42 pm

    The Page‘s Load event fires up sooner than the Button‘s click event. Therefore, at the time it runs, the value of Session("my_name") is still “Dave”.

    If you’d like to set it up correctly, you should either put the Label1.Text = CStr(Session("my_name")) into the PreRender event handler of your page.

    You cut put it into the Button‘s Click event as well (after setting the session value, of course), but I guess that you want to use the session later for storing objects for less trivial purposes.

    (I guess that you’d like to use the session for more advanced purposes later. After all, what would be the point of using session if you only want to change a label’s text?)

    Basically, here is what you want:

    • The Page_Load sets Session(“my_name”) to “Dave” if it is not a postback
    • The Button1_Click sets Session(“my_name”) to the textbox’s text
    • The Page_PreRender sets the label’s text.

    Here’s what’s happening with your current code:

    • The Page_Load sets Session(“my_name”) to “Dave” if it is not a postback
    • The Page_Load sets the label’s text
    • The Button1_Click sets Session(“my_name”) to the textbox’s text

    You can read more about the topic in here: ASP.NET Page Life Cycle Overview.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd argue that you should build a separate "diverse" admin… May 17, 2026 at 2:15 am
  • Editorial Team
    Editorial Team added an answer Lucene can't do this by itself. You will need to… May 17, 2026 at 2:15 am
  • Editorial Team
    Editorial Team added an answer The problem is your parameter -jar. If you specify that,… May 17, 2026 at 2:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have set a session scope object in my session and I want to
I have an ASP.NET web application that takes user input across several forms. Sort
I am working on some PHP classes, I have a session class used to
I have an ASP.NET application that uses Session.SessionID to prevent multiple users viewing the
I have a Web Application (ASP.NET C# for .NET 3.5) that uses the Session
I have a couple of classic ASP pages that require a user to enter
i'm trying to remove an item from a one to many list and have
I have an app that creates and stores a session with a given start
OK, first my simple Domain Model is 2 classes with a one-to-many relationship, a
I was wondering whether it would be possible to change the sqlConnectionString used for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.