ViewState vs local variable
-
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 -
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. JasonIt'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.