473,473 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ViewState question - for tech-heads only

Say I have persisted a DataSet in the ViewState of a page, and that when the
page is posted back I make several references to that dataset like so:

DataSet MyDataSet = (DataSet)ViewState["VsDataSet"]; //C#

Does this have to deserialize the dataset every time it is referenced... or
is it only done once when the page is posted back? I'm just wondering if I
should assign the DataSet to a local variable in the PageLoad method or if
it's OK to continually reference it via the ViewState.

TIA
Nov 18 '05 #1
2 1140
Hi,

ViewState collection is populated from serialized string at LoadViewState
phase once on the postback, so it does not basically deserialize it every
time you reference it. But certainly its not bad habit if you make a
reference to it in local variable (less need for casting).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Gandalf" <ga*****@sauron.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Say I have persisted a DataSet in the ViewState of a page, and that when the
page is posted back I make several references to that dataset like so:

DataSet MyDataSet = (DataSet)ViewState["VsDataSet"]; //C#

Does this have to deserialize the dataset every time it is referenced... or
is it only done once when the page is posted back? I'm just wondering if I
should assign the DataSet to a local variable in the PageLoad method or if
it's OK to continually reference it via the ViewState.

TIA

Nov 18 '05 #2
Thanks for the reply. What I am doing is using a private property rather
than a local variable, something like:

private DataSet PageDataSet
{
get{return (DataSet)ViewState["VsDataSet"];}
set{ViewState["VsDataSet"]=value}
}

This make the persistence to viewstate transparent, but I wanted to be sure
I wasn't incurring any extra overhead.
--

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hi,

ViewState collection is populated from serialized string at LoadViewState
phase once on the postback, so it does not basically deserialize it every
time you reference it. But certainly its not bad habit if you make a
reference to it in local variable (less need for casting).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Gandalf" <ga*****@sauron.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Say I have persisted a DataSet in the ViewState of a page, and that when the page is posted back I make several references to that dataset like so:

DataSet MyDataSet = (DataSet)ViewState["VsDataSet"]; //C#

Does this have to deserialize the dataset every time it is referenced... or is it only done once when the page is posted back? I'm just wondering if I
should assign the DataSet to a local variable in the PageLoad method or if
it's OK to continually reference it via the ViewState.

TIA

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James Glover | last post by:
I need help... I am trying to set the Viewstate of a var on an onclick event and let the page post back to get the new value. When i click the button, the first time though (on the post back) it...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
2
by: ElanKathir | last post by:
Hi ! What is ViewState object ? What is use of that? and I wrote one Function in Server side and also Client Side. I want to run both one by one. Like Validation and Submit. Thanks &...
4
by: A.M | last post by:
Hi, Even I have <@Page ... enableViewState="False"> on top of the page, still my page result has this line in html source: <input type="hidden" name="__VIEWSTATE"...
6
by: clsmith66 | last post by:
Is it possible to store the same information about a control that would be saved in the ViewState in a Session state? I have a page with three treeview controls and if I enable the view state for...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
2
by: Ryan Ternier | last post by:
I'm playing around with Cache and Viewstate. I've made a small little example that reminds me of grade 12: if(!IsPostBack) { ArrayList alTest = new ArrayList(); alTest.Add("This is from...
6
by: paul.hester | last post by:
Hi all, Does anyone know why the ViewState would be empty? When I'm receiving a postback, I can access a posted value using controlName.Value but not ViewState. I have EnableViewState set...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.