asp.net question

Discussion in 'MCSD' started by hisham, Apr 21, 2004.

  1. hisham

    hisham Guest

    does anyone know the diffrance between

    ViewState["variable"]

    and

    Session["variable"]

    and when to use each of them
    ?
     
    hisham, Apr 21, 2004
    #1
    1. Advertising

  2. hisham

    Andrew Guest

    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, Apr 21, 2004
    #2
    1. Advertising

  3. hisham

    Matt Hawley Guest

    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, Apr 21, 2004
    #3
  4. hisham

    Al Manint Guest

    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, Apr 21, 2004
    #4
  5. hisham

    Paul Robson Guest

    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, Apr 21, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?c2FuanU=?=

    information about asp ,oracle,asp.net certification?

    =?Utf-8?B?c2FuanU=?=, May 18, 2005, in forum: Microsoft Certification
    Replies:
    1
    Views:
    577
    Bob Christian
    May 18, 2005
  2. Zabron Muyambo

    Easy Moving from ASP to ASP.NET???

    Zabron Muyambo, Oct 26, 2004, in forum: MCSD
    Replies:
    7
    Views:
    511
    Zabron Muyambo
    Oct 27, 2004
  3. thehobbit
    Replies:
    0
    Views:
    3,779
    thehobbit
    Nov 22, 2006
  4. imman

    session from asp to asp.net

    imman, Feb 20, 2008, in forum: General Computer Support
    Replies:
    0
    Views:
    925
    imman
    Feb 20, 2008
  5. london1919
    Replies:
    1
    Views:
    2,959
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
Loading...

Share This Page