Jump to content

ArrayList Problem.


cyrus_

Recommended Posts

Hi,I have a little problem that make me crazy.I run a Web Application with two buttons Button1 and Button2.here is my code:

public partial class DoFeed : System.Web.UI.Page {      private ArrayList TheItems = new ArrayList();           protected void Page_Load(object sender, EventArgs e){  }      protected void Button1_Click(object sender, EventArgs e)     {                                                                                 OneItem Item = new OneItem();         Item.Title = TitleTXT.Text;         Item.Link = LinkTXT.Text;         TheItems.Add(Item);     }          protected void Button2_Click(object sender, EventArgs e)     {         int m = TheItems.Count;     } }

I click on Button1 but it seems that the arraylist contains just one object and then when i click on Button2 the TheItems.Count is 0.why?

Link to comment
Share on other sites

declare it like this

static ArrayList arr = new ArrayList();

This worked for me...for some reason if not declared as static it does not hold its values. I am using v1.1 so I hope this works for v2.0 as well.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...