Scott on Writing

Musings on technical writing...

Largest. ViewState. Ever.

The ASP.NET DataGrid Web control is notorious for its hefty view state size, but the DropDownList control can hold its own weight as well, especially when it contains a lot of items.  For example, a page containing nothing but a DropDownList populated with ~100 items from a database will yield around 10 KB in view state.  While 10 KB might not seem like much, remember that view state is a two-way penalty - it is sent down with the page's HTML and sent back during postback, thereby increasing both the download and postback time for the end user.

I just finished a page that, I think, will hold record as having the largest view state.  Ever.  Working on a site for a client and he needs a page that has over a dozen DropDownList controls, and each DropDownList has, believe it or not, upwards of 1,000 items.  End view state?  Over 800,000 bytes.  In total, the page was over 2.5 MB in size.  What does this mean for an average dialup user?  Well, they'll have to wait nearly six minutes to download the page, and eight minutes to postback (two minutes to upload the 800 KB of view state, six minutes to download the 2.5 MB again).

Of course, I cut the view state down to a few KB by turning off view state for the page.  It wasn't needed since I wasn't programmatically changing the state of the controls on the page, nor was I using the SelectedIndexChanged event of the DropDownList.  But still, the page weighs in at 1.7 MB, which is still prohibitively large (even though all users are really on an intranet).

posted on Thursday, July 22, 2004 8:37 AM

Feedback

# re: Largest. ViewState. Ever. 7/22/2004 11:18 AM Steve

Thank god for Intranet-ness... between skmMenu and a pretty intenses DataGrid coding, i am running pages 500k and up.....

can anything be done to make skmMenu lighter?

# re: Largest. ViewState. Ever. 7/22/2004 11:22 AM Scott Mitchell

Steve, re: skmMenu, are you using the script as an external script, so it's not embedded in the page? If so, this would help since the client can cache this external .js file.

# re: Largest. ViewState. Ever. 7/22/2004 11:39 AM graz

So Scott, when are you going to write a little app that measures all my pages for view state size? Make it a toolbar utility.

And while I'm requesting things ... how about an article on the top 10 things to reduce view state or code around it? Especially discussing things like datagrid paging :)

# re: Largest. ViewState. Ever. 7/22/2004 11:44 AM Scott Mitchell

Graz, a couple things to check out:

Understanding ASP.NET View State
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp

Fritz Onion's ViewState Decoder:
http://www.pluralsight.com/tools.aspx

Fritz's tool will tell you the ViewState size for a page, and parse it into a nifty little tree too. It's a WinForms app; screenshot available at http://www.pluralsight.com/images/decoderscreenshot.gif.

(To compute view state, I usually just do a view/source and use UltraEdit to select the text and do a Word Count, which inculdes a character count.)

# re: Largest. ViewState. Ever. 7/22/2004 12:43 PM Steve

"Steve, re: skmMenu, are you using the script as an external script, so it's not embedded in the page? If so, this would help since the client can cache this external .js file"

Is this a parameter in skMenu that i missed?

# re: Largest. ViewState. Ever. 7/22/2004 12:45 PM Steve

nm. digging around, i found it

thanks for getting me thinking though

# re: Largest. ViewState. Ever. 7/22/2004 1:02 PM David

We had an app go in the other day and everytime it posted back it would pop up an NT Auth box. They couldnt figure out what was happening so they decided to look into the code. Not only was the dg returning a few thousand rows in viewstate but the developer stored the ds from this in viewstate as well. I am not sure how big the viewstate was but we joked that it was so much it required a God login.

# re: Largest. ViewState. Ever. 7/23/2004 1:16 AM Rasto

Hello, i have some problem and i store viestate in database like: http://weblogs.asp.net/adweigert/archive/2004/03/09/86628.aspx

and maybe next sollution is compress viewstate..

# Rob Howard's 10 Tips for Writing High-Performance Web Applications 11/17/2004 11:33 AM Scott on Writing

# re: Keep countries off viewstate 3/16/2005 11:03 AM Dino Esposito's WebLog

# How Big is Too Big a ViewState? 9/7/2005 9:15 AM Scott on Writing

# re: Largest. ViewState. Ever. 1/2/2006 11:17 AM Chris

I was transporting a lot of view state back and forth ~18000 chars of data and found that as soon as I turned off view state on a few datagrids that did not need it, it went down to ~8000 chars. Unfortunately that all seems to be from the skmmenu. Mind you that is for a user with the most items within the menu based on the user's role, but that is still alot of data. I do have the javascript in a seperate file. Is there any way to reduce this further?

# What's with the MSDN2 Page Sizes? 5/3/2006 5:08 PM Scott on Writing

# re: Largest. ViewState. Ever. 5/23/2006 11:31 AM Ben Strackany

Sounds like a potential candidate for AJAX, so you don't have to preload all that data. My hat currently goes to Anthem.net (http://anthemdotnet.com/)

# On a Related Note - Large Web Forms 3/13/2007 10:53 AM BusinessRx Reading List

Earlier today I posted about large view state issues . Another issue that faces me with this current

# Rob Howard's 10 Tips for Writing High-Performance Web Applications 7/6/2007 2:23 AM Community Blogs

Rob Howard recently authored an article for MSDN Magazine titled 10 Tips for Writing High-Performance

# Rob Howard's 10 Tips for Writing High-Performance Web Applications 7/6/2007 2:24 AM BusinessRx Reading List

Rob Howard recently authored an article for MSDN Magazine titled 10 Tips for Writing High-Performance

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles