What ASP.NET page lifecycle event can I write code in to determine the size of the viewstate that being sent out? Also, is it possible to determine the size without parsing
You can go on the function that is going to writing the viewstate, the SavePageStateToPersistenceMedium. This is the function that also used to compress viewstate...
For example...
public abstract class BasePage : System.Web.UI.Page
{
private ObjectStateFormatter _formatter = new ObjectStateFormatter();
protected override void SavePageStateToPersistenceMedium(object viewState)
{
MemoryStream ms = new MemoryStream();
_formatter.Serialize(ms, viewState);
byte[] viewStateArray = ms.ToArray();
....
}
}
Some reference.
http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx
http://forums.asp.net/p/1139883/3836512.aspx
http://www.dotnetcurry.com/ShowArticle.aspx?ID=67&AspxAutoDetectCookieSupport=1