473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to programmatically determine page and viewstate size ?

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
Nov 18 '05 #1
2 7032
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/articleVi...x?aId=135&pId=

"NewsAccount" <no****@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2
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());
"Michael" <raterus@localhost> wrote in message
news:#5**************@TK2MSFTNGP09.phx.gbl...
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/articleVi...x?aId=135&pId=

"NewsAccount" <no****@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Thompson | last post by:
I have a page that uses a custom object I wrote to build a table. I also have a post back to the page to remove items from that table. When the page loads I can see the viewstate code on the...
2
by: mykidisgollum | last post by:
Greetings, We've recently been working with our site pages' viewstate, turning off unnecessesary viestate items to reduce page size for faster loading. We are also experimenting with using less...
9
by: Rob Meade | last post by:
Hi all, I have a form which is programmatically created from reading values from a database table. There is a 'form' for each DocumentType - when I say form I mean as in a different form will...
5
by: Joe Fallon | last post by:
Is there a good way to measure the size of a page delivered to the browser? Also, how do measure the size of Viewstate? I am just using View Source, saving the text file and looking at the number...
8
by: mark.norgate | last post by:
I've asked this question before, but still haven't solved it, so am asking again. I am programmatically adding a user control to the page in response to a button click. The user control consists...
1
by: RHIZOME | last post by:
I am reparameterizing a SqlDataSource programmatically, using runtime events. This works nicely for on-the-fly search, but sorting and paging are using the original (declared) version of my...
3
by: xeroxero | last post by:
I would like to set the following Page directives in my C# code-behind for ASP.NET 2.0 Web Application Project and also in a ASP.NET 2.0 Web Site. What event should I hook and what should the code...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
6
by: Mike | last post by:
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.