473,800 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to programmaticall y determine page and viewstate size ?

Hi

I'm trying to find a way to programmaticall y 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(HtmlText Writer 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 7079
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.Strin gWriter
Dim localWriter As New HtmlTextWriter( sw)
MyBase.Render(l ocalWriter)
Dim output As String = sw.ToString()
Dim size As Long
size = output.Length()
writer.Write(ou tput)
I'm not quite as sure about viewstate, but this page may help you
http://www.aspalliance.com/articleVi...x?aId=135&pId=

"NewsAccoun t" <no****@nospam. com> wrote in message
news:uM******** ******@TK2MSFTN GP11.phx.gbl...
Hi

I'm trying to find a way to programmaticall y 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(HtmlText Writer 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 SavePageStateTo PersistenceMedi um(object viewState)

{

base.SavePageSt ateToPersistenc eMedium(viewSta te);

LosFormatter format = new LosFormatter();

StringWriter writer = new StringWriter();

format.Serializ e(writer, viewState);

int viewStateLength = writer.ToString ().Length;

To Calculate page size :

protected override void Render(HtmlText Writer writer)

{

StringWriter customWriter = new StringWriter();

HtmlTextWriter localWriter = new HtmlTextWriter( customWriter);

base.Render(loc alWriter);

int pageLength = customWriter.To String().Length ;

writer.Write(cu stomWriter.ToSt ring());
"Michael" <raterus@localh ost> wrote in message
news:#5******** ******@TK2MSFTN GP09.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.Strin gWriter
Dim localWriter As New HtmlTextWriter( sw)
MyBase.Render(l ocalWriter)
Dim output As String = sw.ToString()
Dim size As Long
size = output.Length()
writer.Write(ou tput)
I'm not quite as sure about viewstate, but this page may help you
http://www.aspalliance.com/articleVi...x?aId=135&pId=

"NewsAccoun t" <no****@nospam. com> wrote in message
news:uM******** ******@TK2MSFTN GP11.phx.gbl...
Hi

I'm trying to find a way to programmaticall y 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(HtmlText Writer 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
1831
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 source of the page is about 5 lines. When I post back to remove an item and rebuild the page it works. I view the source of the page and the viewstate code has doubled in size even though I have less data for it to hold. On the second post back I...
2
1503
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 tables etc. What is the best way to determine the amount of data passed from server to client in an ASP.NET page run? Right now the only way we know is to view source, save source and view the file size properties. I believe this may not...
9
1407
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 be displayed depending on the DocumentType. If the querystring contains the DocumenType then the drop down menu is removed and a text box (readonly) is put in its place to show the users what
5
1408
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 of kb in the Properties of the file. Then I delete everything but the viewstate and measue it the same way. 1. Is it accurate? 2. Is there a better way? (I want to measure over 100 pages.) --
8
1998
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 of three dropdowns and seven text boxes. When the button is clicked, I add another control to the page in Click event of the button and populate the three dropdowns. The text boxes are to be populated by the user.
1
1991
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 SqlDataSource. The net effect is that I lose all of my runtime parameters, when I sort or page in a GridView thats bound to my SqlDataSource. The SqlDataSource reverts to its original viewstate from when the page first loaded, when a user clicks a...
3
3049
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 look like? MaintainScrollPositionOnPostback ViewStateEncryptionMode LinePragmas Title
2
15075
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 been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
6
1665
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 storing the data in a Varailble for further use and if they delete the text my varialble is keeping the old data entered plus adding the new data, I only want the new data they enter. text = "Sue, Dave, Tom" the user deletes "Sue, Dave, Tom" ...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.