question about variable in session, viewstate ..

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
 
S

sloan

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.
 
S

Steve

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
 
A

Aidy

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.
 
S

sloan

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")
 
B

Britt

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")
 
G

Guest

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
 
S

Steve

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top