ASP.NET View state manager
In this article I will show you how to reduce view state of your asp.net pages by saving it into server session. This solution is perfect for dashboards but is not advisable if you have a lot of users as this can consume a huge amount of server resources.
Basically It can reduce page view state for up to 80%. In my case the total page size was reduced to 200Kb from about 1Mb 🙂
How it works
It saves and loads view state by overriding the page LoadPageStateFromPersistenceMedium and SavePageStateToPersistenceMedium methods. You can configure it to save to other “Persistent Mediums” as well.
protected override object LoadPageStateFromPersistenceMedium() { //If server side enabled use it, otherwise use original base class implementation if (true == viewStateSvrMgr.GetViewStateSvrMgr().ServerSideEnabled) { return LoadViewState(); } else { return base.LoadPageStateFromPersistenceMedium(); } }
protected override void SavePageStateToPersistenceMedium(object viewState) { if (true == viewStateSvrMgr.GetViewStateSvrMgr().ServerSideEnabled) { SaveViewState(viewState); } else { base.SavePageStateToPersistenceMedium(viewState); } }
When using it you only need to implement from “BasePage” in you pages, the rest is done automatically.
public partial class _Default : BasePage { }
You can download complete solution below.
ViewStateHelper