cyrus_ Posted February 14, 2006 Share Posted February 14, 2006 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 More sharing options...
aspnetguy Posted February 14, 2006 Share Posted February 14, 2006 have you tried declaring the ArrayList like this protected ArrayList TheItems = new ArrayList(); or ArrayList TheItems = new ArrayList(); ???declaring it as private may have an affect on it Link to comment Share on other sites More sharing options...
cyrus_ Posted February 14, 2006 Author Share Posted February 14, 2006 Yes, I didIt is something about pag_load, I think when i click on Button1 it declares the ArrayList one more time and it will be empty,same when i click Button2.I dont know how i save my data Link to comment Share on other sites More sharing options...
aspnetguy Posted February 14, 2006 Share Posted February 14, 2006 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 More sharing options...
cyrus_ Posted February 14, 2006 Author Share Posted February 14, 2006 declare it like thisstatic 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. <{POST_SNAPBACK}> You dont feel goood Link to comment Share on other sites More sharing options...
aspnetguy Posted February 14, 2006 Share Posted February 14, 2006 You dont feel goood<{POST_SNAPBACK}> ???what does that mean??? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now