?
Solved

ViewState vs Session state

Posted on 2006-06-01
7
Medium Priority
?
596 Views
Last Modified: 2006-11-18
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
Comment
Question by:jrmcdona
7 Comments
 
LVL 9

Assisted Solution

by:bele04
bele04 earned 280 total points
ID: 16812847
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
 
LVL 16

Assisted Solution

by:Edwin_C
Edwin_C earned 280 total points
ID: 16812853
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 280 total points
ID: 16813228
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Assisted Solution

by:SKumar_1981
SKumar_1981 earned 280 total points
ID: 16813551
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
 
LVL 12

Assisted Solution

by:deanvanrooyen
deanvanrooyen earned 280 total points
ID: 16815364
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
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 16815379
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
 

Author Comment

by:jrmcdona
ID: 16817667
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question