Go Back   Velocity Reviews > Newsgroups > MCSD
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

MCSD - asp.net question

 
Thread Tools Search this Thread
Old 04-21-2004, 01:23 PM   #1
Default asp.net question


does anyone know the diffrance between

ViewState["variable"]

and

Session["variable"]

and when to use each of them
?



hisham
  Reply With Quote
Old 04-21-2004, 02:27 PM   #2
Andrew
 
Posts: n/a
Default asp.net question
ViewState is posted back (round tripped) to the
Server/Browser and the data is contained in a hidden
control. SessionState is stored on the server and is not
posted back (unless it is required to be displayed of
course ). You must consider issues such as HTML
payload, security, Server loading, data type (ie
Viewstate is serialised and best suited for 'simple' data
types cf SessionState which can handle any .Net datatype.

Both are browser independent.

That's about all I can recall,

Andrew

>-----Original Message-----
>does anyone know the diffrance between
>
>ViewState["variable"]
>
>and
>
>Session["variable"]
>
>and when to use each of them
>?
>
>.
>



Andrew
  Reply With Quote
Old 04-21-2004, 02:28 PM   #3
Matt Hawley
 
Posts: n/a
Default asp.net question
ViewState is state that is stored for a particular ASP.NET WebForm. It holds values between postbacks for a page. ViewState will be lost once you visit another page and return. Session state is a per user way of storing information for that user, like UserID, FirstName, LastName, etc. It can be used to store just about anything unique to that user.

Both come with a penalty hit, however. ViewState is encrypted and sent to the browser in a hidden field "__VIEWSTATE", so if you have a lot of controls on a page that store their state in ViewState, this field can be bloated and increase the size of the page download. This can be trimmed by setting EnableViewstate = False for any control or page if you wish.

Session state, has 3 different methods of storage: InProc, StateServer, SQL Server. InProc uses the in process memory currently running the ASP.NET application at the moment. If you make a change to your web.config or upload a new .DLL, all session is lost. StateServer uses a separate Windows Service to store state outside of the ASP.NET application. Therefore, if you update (like before), session is not lost, except for a server reboot (This is what I/my company use). Both of these scenarios can increase the amount of memory that is used, so you must be cautious to what you place in session. Lastly, storing state in SQL Server alleviates the headache of web farms and server restarts because it uses SQL Server to store its state. The only penalty you will see here is the constant flow of data between your webserver & sql server.

I hope this helps!

Matt Hawley, MCAD .NET
http://www.eworldui.net

does anyone know the diffrance between

ViewState["variable"]

and

Session["variable"]

and when to use each of them
?




Matt Hawley
  Reply With Quote
Old 04-21-2004, 04:24 PM   #4
Al Manint
 
Posts: n/a
Default Re: asp.net question
I think the answers to this question were great. However, with about 2
seconds on MSDN you got enough to answer this question. What is the line
between spoon feeding and helping? I don't want to be an ass but do you
really want to work with someone who can't figure out the difference between
these two things?

I know this has been hit upon many times, I'm just getting frustrated by
questions like this in this newsgroup and other newsgroups. Is it just me?
I'll go away and shut up if so.

--Al MSCD, MCSD.NET, MCDBA and someone who TRIES to answer my own questions
through available sources first, breaks down my attemps in my posts, and
then asks for input.

"hisham" <> wrote in message
news:20d301c4279b$6d263090$...
> does anyone know the diffrance between
>
> ViewState["variable"]
>
> and
>
> Session["variable"]
>
> and when to use each of them
> ?
>





Al Manint
  Reply With Quote
Old 04-21-2004, 04:45 PM   #5
Paul Robson
 
Posts: n/a
Default Re: asp.net question
hisham wrote:
> does anyone know the diffrance between
>
> ViewState["variable"]
>
> and
>
> Session["variable"]
>
> and when to use each of them
> ?


OTOMH Viewstate belongs to the view
(e.g. the current page), SessionState to
the current session




Paul Robson
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: Asign Users in Roles(Array.IndexOf(Of String) method) msandlana Software 0 04-25-2008 06:37 AM
ASP.Net Project Structure Question koraykazgan Software 0 08-10-2007 08:23 AM
ASP.NET 2.0 application does not run in WIN2k3 johnfraj Software 0 04-19-2007 08:27 AM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good God DVD Video 3 04-25-2005 04:19 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good Filthy Mcnasty DVD Video 0 04-25-2005 04:29 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46