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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:17:01+00:00 2026-06-11T17:17:01+00:00

The variables in the partial class _Default get reset in the function call as

  • 0

The variables in the partial class _Default get reset in the function call as mentioned in the code below. But, on marking the properties as static, their values are retained.

My questions is, why does this happen? Doesn’t each function call use same instance of page class?

public partial class _Default : System.Web.UI.Page
{
    public double ValueToConvert { get; set; }
    public double ConvertedValue { get; set; }

    protected void Page_Load(object sender, EventArgs e){}

    protected void btnUC_Click(object sender, EventArgs e)
    {
        //In this method, the non-static properties ValueToConvert and ConvertedValue
        //get reset. But why?
    }

}
  • 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-11T17:17:02+00:00Added an answer on June 11, 2026 at 5:17 pm

    Doesn’t each function call use same instance of page class?

    Well each request will create a new instance of the class. Heck, they could be on different processes or even different machines. If you have multiple method calls within the same request that will use the same instance, but otherwise you need to work out how you expect the state to be propagated. You could propagate it via the client (viewstate) or store it somewhere server-side (e.g. in a database).

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

Sidebar

Related Questions

I am trying to override the Page_PreInit function inside my class _Default which inherits
public partial class introduction : System.Web.UI.Page { static BusinessService bs = null; private static
ASP.NET 4.0 Webforms project. I have the following in my code-behind. public partial class
Using local variables seems advisable in a partial that could be used application-wide to
Are variables declared inside a static block accessible anywhere else? What kind of member
I have two variables in a jquery code and if item.a not exist, it
I am using static variables in my app, lots of them. My question is,
I have a .net application (c#) that goes something like this public partial class
I am using the below code to disable the hotkeys like Alt + f4,
Below you can see my .xaml.cs code. The app opens fine. There are 4

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.