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();
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
ArrayListproperties back to empty. If you want values to be persisted, you have to manage that yourself, either withViewState, orSession, 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.