Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching viewstate?

ViewState Caching

This is a great idea, but it's implemented for SharePoint. Wonder if there is a solution for regular asp.net pages, which does the same, caches viewstates.

like image 448
Stewie Griffin Avatar asked Aug 10 '10 15:08

Stewie Griffin


People also ask

What is ViewState used for?

View state is used automatically by the ASP.NET page framework to persist information that must be preserved between postbacks. This information includes any non-default values of controls. You can also use view state to store application data that is specific to a page.

What is caching in C#?

Caching enables you to store data in memory for rapid access. When the data is accessed again, applications can get the data from the cache instead of retrieving it from the original source. This can improve performance and scalability.

Can application session state be stored in cache?

Session state caching is useful for storing data associated with an HTTP session. Storing this data in a cache allows it to be retrieved quickly and persisted across log-ins.

What is ViewState and control state?

ViewState and ControlState are both mechanisms used in ASP.NET for maintaining data across postbacks. Both are preserved in a hidden field known as _VIEWSTATE. The differences are: 1)ViewState can be disabled while the Control State cannot be disabled.


1 Answers

It's actually quite simple! You just need to override these two methods on your page:

SavePageStateToPersistentMedium()

LoadPageStateFromPersistenceMedium()

In there, you can get the ViewState object tree, serialize it however you want and store it wherever you want (Session, SQL, etc), and instead of returning the entire serialized blob to the browser, just return a unique ID you can use to look it up again next time around.

The idea is covered in painstaking detail here: http://msdn.microsoft.com/en-us/library/ms972976.aspx

like image 135
Rex M Avatar answered Sep 17 '22 23:09

Rex M