473,395 Members | 1,386 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,395 software developers and data experts.

question about variable in session, viewstate ..

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
Aug 20 '07 #1
8 1185
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.
Aug 20 '07 #2

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.

"Britt" <br@ittmail.dewrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
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

Aug 20 '07 #3
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
Britt wrote:
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

Aug 20 '07 #4

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

"Britt" <br@ittmail.dewrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
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

Aug 20 '07 #5
What is functionality of viewstate collection?

"Steve" wrote:
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
Britt wrote:
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
Aug 21 '07 #6
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
Aleks Kleyn wrote:
What is functionality of viewstate collection?

"Steve" wrote:
>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
Britt wrote:
>>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

Aug 21 '07 #7
"Aleks Kleyn" <Al********@discussions.microsoft.comwrote in message
news:33**********************************@microsof t.com...
What is functionality of viewstate collection?
Google is your friend:
http://www.google.co.uk/search?sourc...20&q=ViewState
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Aug 21 '07 #8
So are experienced developers. :)
Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA
Mark Rae [MVP] wrote:
"Aleks Kleyn" <Al********@discussions.microsoft.comwrote in message
news:33**********************************@microsof t.com...
>What is functionality of viewstate collection?

Google is your friend:
http://www.google.co.uk/search?sourc...20&q=ViewState
Aug 21 '07 #9

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

Similar topics

1
by: Das | last post by:
Hi all, I'm using Asp.net. Within a form I have declared declared a public variable. When the form is loaded I set the property for the variable. but it doesn't maintain its state on postback. I...
2
by: Mike P | last post by:
I have the following code in my Page_Load event to populate a listbox from a database : if (!(Page.IsPostBack)) { SqlConnection objConnection = new...
1
by: JCardinal | last post by:
I am saving the viewstate at the server for pocket pc clients to get around the old Invalid Viewstate error. This works perfectly, however when I look at the html source of the page served up to...
5
by: Craig Buchanan | last post by:
I'm using a viewstate key/value to store a serialized instance of a class. If I redirect to another aspx page, the viewstate is lost. Is this the intended behavior of the viewstate? Is there a...
8
by: hb | last post by:
Hi, I need to declare a variable who's value can be preserve through the same ASP.Net page. I tried the following code, only the static variable s2 keeps its value=22 after lnk1_Click followed...
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
8
by: rodchar | last post by:
hey all, is there a way to persist a client-side variable between postbacks? thanks, rodchar
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.