How to programmatically determine page and viewstate size ?

N

NewsAccount

Hi

I'm trying to find a way to programmatically measure the size of the page
sent down to the browser, can't seem to measure the length of what gets
written to the HTML TextWriter in
protected override void Render(HtmlTextWriter writer)
{



Also, I want to find the size of the viewstate when rendering the page. I've
seen a way to get this when posting back, however, I would like to do this
at render time so that I can neatly log this information .

Any ideas ?



Many thanks



Guy
 
M

Michael

You can determine page size by doing this in the Render event (Sorry this
example is in vb.net, but it should be similar in C#)

Dim sw As New System.IO.StringWriter
Dim localWriter As New HtmlTextWriter(sw)
MyBase.Render(localWriter)
Dim output As String = sw.ToString()
Dim size As Long
size = output.Length()
writer.Write(output)


I'm not quite as sure about viewstate, but this page may help you
http://www.aspalliance.com/articleViewer.aspx?aId=135&pId=
 
N

NewsAccount

Thanks very much for the help Michael.

If anyone else is interested here are the C# implementations

To Calculate Viewstate size :
protected override void SavePageStateToPersistenceMedium(object viewState)

{

base.SavePageStateToPersistenceMedium(viewState);

LosFormatter format = new LosFormatter();

StringWriter writer = new StringWriter();

format.Serialize(writer, viewState);

int viewStateLength = writer.ToString().Length;



To Calculate page size :

protected override void Render(HtmlTextWriter writer)

{

StringWriter customWriter = new StringWriter();

HtmlTextWriter localWriter = new HtmlTextWriter(customWriter);

base.Render(localWriter);

int pageLength = customWriter.ToString().Length;

writer.Write(customWriter.ToString());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top