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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:44:50+00:00 2026-06-07T10:44:50+00:00

I have a C# website that has a a user control where I initialize

  • 0

I have a C# website that has a a user control where I initialize a series of private variables at the top of the user control:

using System.IO;

namespace FF.Core
{

    public partial class _Job : System.Web.UI.UserControl
    {
        private static long _JobID = 0;
        private static string _JobNumber = String.Empty;

I have dragged this user control on an .aspx page the mark up is as follows:

<%@ Register Src="_Job.ascx" TagName="_Job" TagPrefix="uc1" %>

<uc1:_JobDataEntry ID="_Job" runat="server" />

My application will launch multiple pages that contain this user control. It appears that after the first instance is launched the user control is not reinitialized ie the _JobID is not set back to 0 instead it contains the value of the previous loaded _JobID. I was under the impression because I’m launching a new page the _JobID would be set back to 0. I could initialize my variables in page load but I wanted to understand why this is happening and understand the best way to reuse a user control. Each of my new pages is being launched in a new browser window “target=_blank”

Thanks !

  • 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-07T10:44:51+00:00Added an answer on June 7, 2026 at 10:44 am

    You have static variables, and those keep their state as long as you web app is running. Static variables are shared among all instances of a given class. That works for something like winforms, but not in web apps. Generally avoid static variables in web apps and web services, and also in class libraries that will be used by web apps/services.

    Simply make those a private NOT static variable. And do a search for static variable in your app, and convert them to instance variables (unless you have a really good reason to keep them static.

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

Sidebar

Related Questions

I have a user control on a page of a website that generates a
I have created a user control that has an asp:login control in it. I
So basically I have website that has names of cities that can be checked
I have a website that has highly granulised access and hence requires many web.config
I have a website that has one database I have also Desktop apps that
I have a website that has products list page and product detail page .
I have a website that has approx 1000 different strings in a mysql database
I have a website that has a relative path to a stylesheet that looks
I have a travel related website that has been online for several years (since
I have a section of a website that has three divs next to each

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.