I have a little problem with ArrayList that make me crazy,
I have a usual Web Application that contains two Buttons,
When i click on Button1 it would add an object to MyArrayList and Button2 Shows the Objects.
but MyArrayList.Count is Zero allways.
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; //it is zero allways
for(int i=0; i
}
}
Anwar BuchooPosted Feb 22, 2006, 1:18 AM
But, it's not always advisable to save data into Session or ViewState object as this can slow down the loading of the web page and consume memory for a amount of time.
Think, instead, of using a hidden field within your web form (.aspx) to save the data.
Rgds.
NB: Just for information, the data of variables are lost when the form is posted back.
kourosh salehPosted Feb 15, 2006, 2:26 AM
I have tested it but it doesn't work,
the problem is about "state" when you make a event in a web page all controls were recreated and you must save the state, by session or ViewState,
I have solve my problem thanks,
I am not good to explain,
Thang Truong Nguyen QuocPosted Feb 14, 2006, 10:39 PM
Regards,
ThangTruong
Mohammed SajidPosted Feb 14, 2006, 10:38 AM
Hi,
Do the modifications as below and it should work.
public partial class DoFeed : System.Web.UI.Page
{
private ArrayList TheItems = new ArrayList();
// Declaration should go here......
OneItem Item;
protected void Page_Load(object sender, EventArgs e){ }
protected void Button1_Click(object sender, EventArgs e)
{
//OneItem Item = new OneItem();
// Instantiate here....
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; //it is zero allways
for(int i=0; i
}
}
Regards,
Mohammed Sajid