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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:59:18+00:00 2026-06-07T18:59:18+00:00

I have arraylists in the code behind and they don’t keep the values I

  • 0

I have arraylists in the code behind and they don’t keep the values I add to them. I tried making them public static and that works but the problem with that is I don’t want the values kept after the user’s completed the form. I would like them cleared when they need to use the form again. The values do get added when they aren’t set as being public static but by the time the next item is added on the form the values from the first item are gone from the arraylists. Please help.

namespace Application
{
    public partial class Enquiry : System.Web.UI.Page
    {
         ArrayList Dates = new ArrayList();
         ArrayList Dates2 = new ArrayList();
         ArrayList Cost = new ArrayList();
  • 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-07T18:59:20+00:00Added an answer on June 7, 2026 at 6:59 pm

    ASP.NET web pages are stateless. Class properties are not automatically saved and restored upon postback; every time you reload your page, a new instance of the page class is instantiated, resetting your private ArrayList properties back to empty. If you want values to be persisted, you have to manage that yourself, either with ViewState, or Session, or by simply rebuilding your lists on every page load.

    You may need to research the ASP.NET page life cycle. It might make things more clear.

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

Sidebar

Related Questions

I'm trying to have nested ArrayLists, and tried to add a new ArrayList as
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
please have a look at the following code import java.util.ArrayList; import java.util.List; public class
I have the below java code: List<SomePojo> list = new ArrayList<SomePojo>(); //add 100 SomePojo
I have two arraylists. One contains filenames and the other contains failurecount. These values
I have a list box control: <asp:ListBox runat=server id=lbox autoPostBack=true /> The code behind
I have 2 arraylists. One is principleList which contains integer values that denotes roles
In WPF C#, in code behind, I have to dynamically create an Array of
In my code I have a number of ArrayLists that are passed into a
I have tried for the last two days to get some code to work,

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.