Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Why bother using ViewState?

Why bother using ViewState?

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CoolAmir
    wrote on last edited by
    #1

    Hi guys =) I'm wondering why ViewState is used while Session & Cache are out there? :~ Thanx guys

    A 1 Reply Last reply
    0
    • C CoolAmir

      Hi guys =) I'm wondering why ViewState is used while Session & Cache are out there? :~ Thanx guys

      A Offline
      A Offline
      Ali Iqbal Khan
      wrote on last edited by
      #2

      See this link and you'll find the reason http://www.w3schools.com/aspnet/aspnet_viewstate.asp[^] Ali

      C 1 Reply Last reply
      0
      • A Ali Iqbal Khan

        See this link and you'll find the reason http://www.w3schools.com/aspnet/aspnet_viewstate.asp[^] Ali

        C Offline
        C Offline
        CoolAmir
        wrote on last edited by
        #3

        Thanx Ali. I better make my question more clear. Better to say "Why Microsoft bothered inserting form's state info in hidden fields in HTML files while they (!) could use Session or Cache?" ;P

        S M 2 Replies Last reply
        0
        • C CoolAmir

          Thanx Ali. I better make my question more clear. Better to say "Why Microsoft bothered inserting form's state info in hidden fields in HTML files while they (!) could use Session or Cache?" ;P

          S Offline
          S Offline
          Sebastien Lachance
          wrote on last edited by
          #4

          I think this is because of performance. My Blog

          1 Reply Last reply
          0
          • C CoolAmir

            Thanx Ali. I better make my question more clear. Better to say "Why Microsoft bothered inserting form's state info in hidden fields in HTML files while they (!) could use Session or Cache?" ;P

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Hi there, + As you already know that ViewState is used to store page-specific data, while Session is for user-specific, and Cache is to store data which can be accessed by all users. If you use Session to store a page-specific variable, the sample code is something like this:

            Session["PageID+Key"] = value;

            also for the Cache object:

            Cache["PageID+UserID+Key"] = value;

            I believe that this's not a good practice to follow. + The Session object might consume lots of memory to store data, then it can affect the performance of the application. + Data saved in the Cache object can be accessible to all users of the application, so you need to take this thing into account when you use the Cache object to store page-specific data. Well, just some ideas.

            C 1 Reply Last reply
            0
            • M minhpc_bk

              Hi there, + As you already know that ViewState is used to store page-specific data, while Session is for user-specific, and Cache is to store data which can be accessed by all users. If you use Session to store a page-specific variable, the sample code is something like this:

              Session["PageID+Key"] = value;

              also for the Cache object:

              Cache["PageID+UserID+Key"] = value;

              I believe that this's not a good practice to follow. + The Session object might consume lots of memory to store data, then it can affect the performance of the application. + Data saved in the Cache object can be accessible to all users of the application, so you need to take this thing into account when you use the Cache object to store page-specific data. Well, just some ideas.

              C Offline
              C Offline
              CoolAmir
              wrote on last edited by
              #6

              I got some ideas now. ( by reading replies here) I guess because these data are often useless to other web forms, they do not need to exist further than current page/request scope. :^) Great comments, thanx :-D

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups