ArrayList on my Page
-
I am creating this page where I am reading from the database using a SqlDataReader and Loading the info into an ArrayList. The ArrayList is a class member and the ArrayList object has been created in the class constructor, therefore, this object should be visible to all other members of the class. However, if I add some objects to the ArrayList in a MenuItem_Click and then try to read those added objects from a Button_Click, it shows the ArrayList is empty - which seems quite surprising. Obviously I am missing something. Any help? Thanks. Ekjon
-
I am creating this page where I am reading from the database using a SqlDataReader and Loading the info into an ArrayList. The ArrayList is a class member and the ArrayList object has been created in the class constructor, therefore, this object should be visible to all other members of the class. However, if I add some objects to the ArrayList in a MenuItem_Click and then try to read those added objects from a Button_Click, it shows the ArrayList is empty - which seems quite surprising. Obviously I am missing something. Any help? Thanks. Ekjon
The two clicks happen on different postbacks, so there's a new list each time.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
The two clicks happen on different postbacks, so there's a new list each time.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Hi Christian, Thanks for the reply. I worked mostly with non-web-based apps, so I thought if I create the ArrayList in the costructor, its always the same List unless the page is disposed. So, what would be the solution? How do I get the same Even if I use a DataSet, is it gonna behave the same way? Please help. Thanks. Ekjon
-
Hi Christian, Thanks for the reply. I worked mostly with non-web-based apps, so I thought if I create the ArrayList in the costructor, its always the same List unless the page is disposed. So, what would be the solution? How do I get the same Even if I use a DataSet, is it gonna behave the same way? Please help. Thanks. Ekjon
Everything is going to work the same way, your options are: 1 - store it in viewstate ( this means it goes down to the client every time, making it insecure, and also making your pages huge ) 2 - store it in the session ( I don't like this if I can avoid it ) 3 - don't store it at all, redirect so some value is on your URL that allows you to rebuild the data from the database.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Everything is going to work the same way, your options are: 1 - store it in viewstate ( this means it goes down to the client every time, making it insecure, and also making your pages huge ) 2 - store it in the session ( I don't like this if I can avoid it ) 3 - don't store it at all, redirect so some value is on your URL that allows you to rebuild the data from the database.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thanks so much Christian. It was really helpful. I thought there could be a better way that I don't know, but looks like there isn't. Off course I'll not use ViewState, probably, I'll use the Session.