Save array in Session object 
Author Message
 Save array in Session object

I want to know that can I save arrays in Session object, so I can use in
other pages??

If so, how's it??

Best Regards,

Eric Yum



Sat, 05 Feb 2005 00:08:32 GMT  
 Save array in Session object

Quote:

> I want to know that can I save arrays in Session object, so I can use
> in other pages??

> If so, how's it??


<html>
<body>
<%
if(Session("myArray")){
  var myArray = Session("myArray");
  Response.Write("found myArray<br>");
  Response.Write("myArray[0] contains: " + myArray[0] + "<br>");
Quote:
}else{

  var myArray = ["aaa","bbb"];
  Session("myArray") = myArray;
  Response.Write("saved myArray<br>");
  Response.Write("Refresh the page to fetch it...<br>");
Quote:
}

%>
</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 00:31:41 GMT  
 Save array in Session object
Dim sSample
Dim vSample
Dim i

sSample = "Hello,Test,Wow,Sweet,Cool"
vSample = Split(sSample, ",")

Session("Array") = vSample

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next


Quote:
> I want to know that can I save arrays in Session object, so I can use in
> other pages??

> If so, how's it??

> Best Regards,

> Eric Yum



Sat, 05 Feb 2005 05:16:29 GMT  
 Save array in Session object
Accessing the saved array as:

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next

returns a complete copy of the array on every reference to Session("Array").

Perhaps not a big issue on small arrays, but on larger arrays it is more efficent to get a local copy of the saved array and work with that...

savedArray = Session("Array")
If IsArray(savedArray) Then
    For i = 0 to Ubound(savedArray)
        Response.Write(savedArray(i) & "<BR>")
    Next
End If

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 05:39:42 GMT  
 Save array in Session object
Fair enough.   :)



Accessing the saved array as:

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next

returns a complete copy of the array on every reference to Session("Array").

Perhaps not a big issue on small arrays, but on larger arrays it is more
efficent to get a local copy of the saved array and work with that...

savedArray = Session("Array")
If IsArray(savedArray) Then
    For i = 0 to Ubound(savedArray)
        Response.Write(savedArray(i) & "<BR>")
    Next
End If

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 05:47:17 GMT  
 Save array in Session object

Quote:

> Fair enough.   :)

It's also necessary if the saved array is to be modified...

Session("Array")(i) = "new value"

won't update the Session copy of the array, but the following will...

savedArray = Session("Array")
.
.
.
savedArray(i) = "new value"
.
.
.
Session("Array") = savedArray

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 22:45:26 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Save array in Session object

2. Having trouble saving array in Session object

3. Save array in Session object

4. Saving Objects in Session variables

5. How to delete an array only from the Session Object

6. Passing names of arrays stored in session object to function

7. Passing Array to Session Variable Then back to Array

8. How to save object with array members to file

9. Passing a valid Session Object from .NET to VB 6 objects

10. Object caching using session object

11. Need to Access ASP Session Objects from External COM Object

12. An intrinsic object cannot be stored within the Session object

 

 
Powered by phpBB® Forum Software