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 9077197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:17:04+00:00 2026-06-16T19:17:04+00:00

Does static variables retain their values across user sessions? I have a ASP.NET web

  • 0

Does static variables retain their values across user sessions?

I have a ASP.NET web application where I have two buttons. One for setting the static variable value, another for Showing the static variable value.

namespace WebApplication1
{   

public partial class WebForm1 : System.Web.UI.Page
{
    public static int customerID;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ButtonSetCustomerID_Click(object sender, EventArgs e)
    {
        customerID = Convert.ToInt32(TextBox1.Text);
    }

    protected void ButtonGetCustomerID_Click(object sender, EventArgs e)
    {
        Label1.Text = Convert.ToString(customerID);
    }
}

}

While this works in single-user environment, What happens if there are 2 users simultaneously logged in from two computers, User 1 sets the value as 100, then User 2 sets the value as 200. after that user 1 invokes the Get Value button. What will he see as the value?

  • 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-06-16T19:17:05+00:00Added an answer on June 16, 2026 at 7:17 pm

    Does static variables retain their values across user sessions?

    Yes, that’s why you should be VERY careful when you use static variables in a web app. You will run in concurrency issues as more than one thread servicing a request can modify the value of the variable.

    While this works in single-user environment, What happens if there are
    2 users simultaneously logged in from two computers, User 1 sets the
    value as 100, then User 2 sets the value as 200. after that user 1
    invokes the Get Value button. What will he see as the value?

    The user will see 200 afterwards.

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

Sidebar

Related Questions

When C says start-up values of global[/static] variables are zero, does it mean also
Static variables in ASP.NET caught me off guard today. Then i became freaked out,
I have been wondering for a while already how does static variables work regarding
I've read that JavaScript does not really have static variables(when i say static, I
I can declare private static member variables in a class, but what does it
If I have a class called myclass does having static methods within the class
I would like to have a mapping function that does this: public static void
I have a static util class that does some string manipulation on a bit
How long do PHP static variables persist, i.e. how long does a PHP run
i want to know that , is finish(); call effect static variables.? does static

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.