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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:23:38+00:00 2026-06-07T20:23:38+00:00

I have a global variable that I’m referencing in a ASP.NET web page update

  • 0

I have a global variable that I’m referencing in a ASP.NET web page update panel. Here’s what happens in the update panel:

    accidentListType.Add(Convert.ToString(AccidentDescription.SelectedItem));
        if (Atfault.Checked)
        {
            accidentAtFault.Add("True");
        }
        else accidentAtFault.Add("False");
        DateTime newDate = new DateTime(Convert.ToInt32(accidentyear.Text), Convert.ToInt32(accidentmonth.Text), 1);
        accidentListDate.Add(newDate);
        TestAccidentLabel.Text = "Success! " + newDate.ToString();

Basically what happens is a list gets another added member every time a button is clicked. But every time it runs through the code, the new index mysteriously gets deleted, so when I go to add all of the accidents to the database, there’s no accidents to add. And I can’t add them dynamically, because one of the inputs to the accident database is the Identity from another table, which I pull when the table gets created, so I have to add them all after anyways.

Can anyone help?
P.S. This is my first time posting, so apologies if it’s messy or anything.

  • 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-07T20:23:40+00:00Added an answer on June 7, 2026 at 8:23 pm

    There are 2 things that you are missing. Though your list is Global, since after every request the page object is destroyed, until and unless you keep the list in Session, the values would not persist. Also, you have to reuse the list that you have kept in session for adding any new value. Do as following.

    //at the start of block
    //check if there is anything in Session
    //if not, create a new list
    if(Session["accidentListType"] == null)
       accidentListType = new List<string>();
    else //else a list already exists in session , use this list and add object to this list
      accidentListType = Session["accidentListType"] as List<string>;
    
    //do your processing, as you are doing
    
    //and at the end of bloack store the object to the session
    Session["accidentListType"] = accidentListType
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a global variable that is an instance of my custom class. How
I have a vector declared as a global variable that I need to be
If i have global variable in A.dll, that depends on global variable in B.dll
Suppose I have a program that initializes a global variable for use by threads,
I have a recursion function that parses an object/array with a global variable. If
I have a js file test.js that contains a global variable global_var and a
I have a global variables that I am using as a default variable. Depending
For example, I have $theme global variable that is defined in the configuration file,
So in jQuery, I have a global variable currentSubNav that stores a current visible
I have a global variable MyGlobalVar and some code that looks like this: var

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.