• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

ViewState vs Session state

Hi,

I have a datagrid that has a dataset as its datasource.

If I store the dataset in viewstate and makes changes to the grid. Does the viewstate capture these changes automatically?

Or do you have to update the viewstate manually after each change or via looping through the rows at the end.

Coming from winforms programming so having difficult not being able to maintain the state of the DataSet automatically as each change occurs.

thanks
Jordan
0
jrmcdona
Asked:
jrmcdona
5 Solutions
 
bele04Commented:
Hi,

The answer to your question would be "no".  Viewstate wouldn't be able to capture those changes automatically if you change something in your grid.  You will have to set it again like you did the first time everytime you have changes in your datagrid.  Same goes with using Session.  The only difference between these two (session and viewstate) is that viewstate's lifespan is only within the page where it was created unlike session where it can be called anywhere in your website.

-bele04-
0
 
Edwin_CCommented:
After binding the dataset to the datagrid, the datagrid is on its own.  Changes will not be applied to the original data source automatically.  You need to update the corresponding rows in the dataset (inside UpdateCommand of the datagrid) after every update and then save the dataset to either the ViewState (if you need to use it in the WebForm later) or the database.  You do not need to loop through the whole grid.

0
 
Bob LearnedCommented:
I would avoid using the ViewState for this type of caching.  It will affect the performance of the page response poorly, since the ViewState is Base-64 encoded.  I agree that the Session variables live on outside of the page.  Other options are (1) cookie (poor), or Cache (better).  Either way, you will have to keep these up-to-date, as they are only one-way storage locations.

Bob
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
SKumar_1981Commented:
You need to update the corresponding rows in the dataset (inside UpdateCommand of the datagrid) after every update and then save the dataset to either the ViewState (if you need to use it in the WebForm later) or the database.The answer to your question would be "no".  Viewstate wouldn't be able to capture those changes automatically if you change something in your grid.
Regards,
skumar
0
 
deanvanrooyenCommented:
hi,

I use session for storing a dataset, but only because the datatable is very small and it is used on the same page as the grid and corresponding requests, be carefull when storing large amounts of data in session variables as it will chew up memory if the data is large and more than a few users use it.
0
 
deanvanrooyenCommented:
asp.net uses a disconnected data model, once the html is rendered the grid is disconnected from the datasource, you have to update the datasource as discribed above and then rebind the grid to the datasource to reflect the changes.
0
 
jrmcdonaAuthor Commented:
thanks everybody for the tips. i seem to have it working now.

I skipped the idea of messing with the viewstate. Going with storing the value in the cache seems to get me what i need in my scenario.

thanks
Jordan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now