A
abcd
My application is using ASP.NET 3.0 and My ASPX pages contain Master page,
and content page. The content page (.aspx) has various User controls (ascx).
My page view state is significantly large and I am looking for some smart way
to rfeduce the page size. So I indentified to manipulate ViewState. When page
is posted I will park the ViewState on Server and viewState will not move
back and forth. I am doing code as below in Page level by overrriding below
methods.
protected override void SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Cache.Add(str, viewState, null,
DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
CacheItemPriority.Default, null);
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return Cache[str];
}
This is not working good for me. My pages get invalid viewState errors. I am
using Workflows too. Any idea how these methods can be better tuned when a
page contains multiple user controls.
Thanks
and content page. The content page (.aspx) has various User controls (ascx).
My page view state is significantly large and I am looking for some smart way
to rfeduce the page size. So I indentified to manipulate ViewState. When page
is posted I will park the ViewState on Server and viewState will not move
back and forth. I am doing code as below in Page level by overrriding below
methods.
protected override void SavePageStateToPersistenceMedium(object viewState)
{
string str = "VIEWSTATE_" + Request.UserHostAddress + "_" +
DateTime.Now.Ticks.ToString();
Cache.Add(str, viewState, null,
DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero,
CacheItemPriority.Default, null);
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
string str = Request.Form["__VIEWSTATE_KEY"];
if (!str.StartsWith("VIEWSTATE_"))
{
throw new Exception("Invalid viewstate key:" + str);
}
return Cache[str];
}
This is not working good for me. My pages get invalid viewState errors. I am
using Workflows too. Any idea how these methods can be better tuned when a
page contains multiple user controls.
Thanks