question about variable in session, viewstate ..

  • Thread starter Thread starter Britt
  • Start date Start date
B

Britt

Hi,

when uing session("myvar"), or viewstate("myvar") or cache("myvar), are the
values always strings?
I mean:

dim dt as date
viewstate("test")=dt
.....
dt=vieswtate("test")

Does here occur a conversion first from date to string, then from string to
date or the value remains always a date?


Thanks
Britt
 
You have to cast the object.


Employee e = new Employee();

viewstate("test")=e;


Employee anotherEmp = ViewState["test"] as Employee;

also, you may have to set the [Serializable] attribute for ViewState, and
non In Proc Session usage.
 
The values are of type "Object", so you can store just about anything in
there. In your code, it's storing a Date object in ViewState since
that's what you added in there.


Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
are the values always strings?

No, you can store anything in the session.
Does here occur a conversion first from date to string, then from string
to date or the value remains always a date?

Not 100% on casting in VB, but there should be no conversion from string to
date.
 
If you'd turn on

Option Explicit ON
Option Strict ON

You'd see this much earlier (that its an object). And that you'd have to
use some casting or convert function.


Convert.ToString ( ViewState("test") )

OR

ctype ( Employee , ViewState ("employeekey")
 
Thanks to all

sloan said:
If you'd turn on

Option Explicit ON
Option Strict ON

You'd see this much earlier (that its an object). And that you'd have to
use some casting or convert function.


Convert.ToString ( ViewState("test") )

OR

ctype ( Employee , ViewState ("employeekey")
 
What is functionality of viewstate collection?

Steve said:
The values are of type "Object", so you can store just about anything in
there. In your code, it's storing a Date object in ViewState since
that's what you added in there.


Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
That's a client-side caching mechanism, whereas SessionState is server
side. ViewState is actually embedded in the HTML page (near the top),
and is sent back and forth between the server and client. This is how it
works. Other than that, they serve the same purpose. For "light"
caching, ViewState works great, and there's virtually NO performance hit
on the server. You just can't really store a LOT of data here because of
how large the HTML page gets.


Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
 
Back
Top