Friday, March 16, 2012

Passing an array as a session variable

I have 2 asp.net forms. In the first form I create a one dimensional array and copy that array into a session object. In the second form I want to read the elements of that array. Everything I've tried results in either a casting error, a late binding error or nothing at all. The following code shows what Iwant to do.

Form one: Dim aArray(2) as stringaArray(0) = "zero"aArray(1) = "one"Session("PassArray") = aArray
Form two: Dim aTest(2) as stringaTest(0) = CType(Session("PassArray(0)"), String)aTest(1) = CType(Session("PassArray(1)"), String)When I run form two in the editor, I can Watch Session("PassArray") and see:Session("PassArray") {System.Array} object-- (0) "zero" string-- (1) "one" stringSo I know it's there and available, but how do I read the extents.

Could really use a simple code example to explain what I'm doing wrong.

Hi,

Use this on the second form:

Dim aTest() As String = CType(Session("PassArray"), String())


That did it. Thank you.

0 comments:

Post a Comment