473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Problem saving arraylist to viewstate


I'm trying to save some ArrayLists to viewstate
and then use them as DataSources for dropdownboxes.

The code looks like this:

'DptList is a arraylist variable local to this procedure

'...populate DptList
viewstate("Dept01") = DptList
DptList.Clear()
'...populate DptList
viewstate("Dept02") = DptList
DptList.Clear() 'Comment this line and it works

When I try to use viewstate("Dept01") in another procedure
as the datasource it doesn't work. I cast this back to
an arraylist and the count is 0.

If I comment out the second DptList.Clear() it works fine.
I'm stumped.
This is all on the initial load of the page.

TIA
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
3 1811
Car1.Driver = Joe
Joe.Kill()
Resurrect(Joe)
Car2.Driver = Joe
Joe.Kill()

Is the driver of Car1 still alive? (No, you killed him after resurrecting
him)

Car1.Driver = Joe
Joe.Kill()
Resurrect(Joe)
Car2.Driver = Joe

Is the driver of car1 still alive? (Yes, you resurrected him after killing
him)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Jim Corey" <jc****@nospamcharter.net> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...

I'm trying to save some ArrayLists to viewstate
and then use them as DataSources for dropdownboxes.

The code looks like this:

'DptList is a arraylist variable local to this procedure

'...populate DptList
viewstate("Dept01") = DptList
DptList.Clear()
'...populate DptList
viewstate("Dept02") = DptList
DptList.Clear() 'Comment this line and it works

When I try to use viewstate("Dept01") in another procedure
as the datasource it doesn't work. I cast this back to
an arraylist and the count is 0.

If I comment out the second DptList.Clear() it works fine.
I'm stumped.
This is all on the initial load of the page.

TIA
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Well, yes.
I guess I discounted this because (1) the first arraylist
displayed (in the dropdown) as it existed before it got
cleared the first time, and (2) I somehow hoped that
creating a viewstate variable wouldn't maintain the reference to the
arraylist. (If that's how you phrase it).

Thanks, I'll go play with it some more.

Jim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
viewstate serializes your objects at render time (it will not deserialize
until the postback). this means its just a reference to the passed object.
therefore viewstate("Dept01") and viewstate("Dept02") both reference the
same object (DptList).

note: on postback when deserialized, viewstate("Dept01") and
viewstate("Dept02") will reference two seperate arraylists.

-- bruce (sqlwork.com)

"Jim Corey" <jc****@nospamcharter.net> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl...

I'm trying to save some ArrayLists to viewstate
and then use them as DataSources for dropdownboxes.

The code looks like this:

'DptList is a arraylist variable local to this procedure

'...populate DptList
viewstate("Dept01") = DptList
DptList.Clear()
'...populate DptList
viewstate("Dept02") = DptList
DptList.Clear() 'Comment this line and it works

When I try to use viewstate("Dept01") in another procedure
as the datasource it doesn't work. I cast this back to
an arraylist and the count is 0.

If I comment out the second DptList.Clear() it works fine.
I'm stumped.
This is all on the initial load of the page.

TIA
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephen | last post by:
I have the following code working in order to create an array list and populate a datagrid however everytime i click my button the first item in the array and the first row in the datagrid are...
4
by: rushikesh.joshi | last post by:
Hi All, I want to create custom control by using Web.UI.WebControls.Calendar, in which I want to set few days with different color. I had created two property to set the color and storing in...
2
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set...
6
by: thanigaimani83 | last post by:
Hi guys. i can explain for my doubt with example.see.my table have multiple type of employee details like as Mangemment,Programmer,Designers,Accountants,ContractEmployees.Each type of department...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.