View state

Question posted in Computer Software on 12 2009
Rate question difficulty level 0 Votes
When to use view state ?
 
 
6 Answers
 

View state is a good way to store data in between postbacks, because it doesn't take up any memory on the server side and it doesn't impose any arbitrary usage limits (such as a timeout). So, what might force you to abandon view state for another type of state management? Here are three possible reasons:


• You need to store mission-critical data that the user cannot be allowed to tamper with. (An ingenious user could modify the view state information in a postback request.) In this case, consider session state.


• You need to store information that will be used by multiple pages. In this case, consider session state, cookies, or the query string.


• You need to store an extremely large amount of information, and you don't want to slow down page transmission times. In this case, consider using a database, or possibly session state.




Remember, any data that you put in the view state will be part of the data stream that goes to the client and then comes back to the server, so be very careful while putting large chunks of data in the ViewState!

credits : http://www.beansoftware.com/ASP.NET-Tutorials/ViewState-In-ASP.NET.aspx


12/05/2009
 
 
I think that the 3rd case when you are using large set of data, you should be only making a DB call and not storing the information in Session. Making a trip to the db is ideal for situations like that. Most of the times when it is being done right it is not expensive. Session and view state should be used for temporarily holding small chunks of data.

12/07/2009
 
 
Viewstate must be used:
- on Intranet system only;
- relatively simple interfaces;
- low data density (short datasets on repeater, for example);
- relatively powerful workstations (HTML parsing performance);

In general, it is better to keep viewstate in database, because:
- it is better for system performance;
- more secure;

12/08/2009
 
 
Viewstate is stored in the client page, so if you put a lot of data into the viewstate, then you are sending a lot of data in the page from server to client.
More data in page = slower page service.

After that, the discussion is theoretical.

12/08/2009
 
 
Could it not be said that calling a database before rendering the next page is actually slower than using viewstate so you would gain little if not actually lose performance. It would not work for extremely high demand sites.

12/08/2009
 
 
What about this: A chunk of data that would be common to every user on your site: would you still want to query it off the DB every time? No - you'd rather use the Cache object or if it is a dataset that's going to be constant for the user (Identity) then store it in session. DB calls should only be made when absolutely necessary.

12/13/2009
 
 
Add an answer*
 
Your name
Email
 
Location: United States
c# asp.net .net

add a question

arrow_blue


Now hiring!
---------------------------
---------------------------
---------------------------
---------------------------
Mercer 
---------------------------
---------------------------
---------------------------