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
  1. Home
  2. Web Development
  3. ASP.NET
  4. ViewState vs local variable

ViewState vs local variable

Scheduled Pinned Locked Moved ASP.NET
visual-studiojsontutorialquestiondiscussion
2 Posts 2 Posters 0 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.
  • J Offline
    J Offline
    Jason Pease
    wrote on last edited by
    #1

    Does anyone know how expensive calls to extract objects from the ViewState are? I'm wondering if it is worthwhile to cache the objects I extract from it into local variables in my code behind. To give you an example, this is what I currently do to store the previous sort column of a datagrid. In order to shield the rest of the page from the implementation I use to store the value I use a private property. private string _previousSortExpression; private string previousSortExpression { _____get _____{ __________if( this._previousSortExpression == null ) __________{ _______________this._previousSortExpression = (string)ViewState[ "_previousSortExpression" ]; __________} __________return this._previousSortExpression; _____} _____set _____{ __________this._previousSortExpression = value; __________ViewState[ "_previousSortExpression" ] = value; _____} } This method prevents multiple calls to get something from the ViewState, but I'm wondering if it's worth the time and space to add this extra logic. Any thoughts are appreciated. Jason

    T 1 Reply Last reply
    0
    • J Jason Pease

      Does anyone know how expensive calls to extract objects from the ViewState are? I'm wondering if it is worthwhile to cache the objects I extract from it into local variables in my code behind. To give you an example, this is what I currently do to store the previous sort column of a datagrid. In order to shield the rest of the page from the implementation I use to store the value I use a private property. private string _previousSortExpression; private string previousSortExpression { _____get _____{ __________if( this._previousSortExpression == null ) __________{ _______________this._previousSortExpression = (string)ViewState[ "_previousSortExpression" ]; __________} __________return this._previousSortExpression; _____} _____set _____{ __________this._previousSortExpression = value; __________ViewState[ "_previousSortExpression" ] = value; _____} } This method prevents multiple calls to get something from the ViewState, but I'm wondering if it's worth the time and space to add this extra logic. Any thoughts are appreciated. Jason

      T Offline
      T Offline
      TylerBrinks
      wrote on last edited by
      #2

      It's not expensive to store objects in the view state. It's just a collection. The expensive part is when you have a large ViewState and it's serialized to the client's browser in the form of a hidden field. Bloated ViewStates slow page loading.

      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