Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is acceptable size of ViewState [closed]

just wanna ask what is acceptable size of ViewState per page? What is the level I should start worried.
Is there any objective measurement for viewstate size?

Thanks for any opinion :-) Cheers, X.

like image 985
Jaroslav Urban Avatar asked May 27 '10 13:05

Jaroslav Urban


People also ask

What is ViewState value?

What is ViewState? ViewState is a client side mechanism. It stores the value in the page itself. Preserving the value of page controls between client to server and server to client is called "roundtrip". It stores the page or control value in the mode of hidden fields.

How do you calculate ViewState?

You can check viewstate on executed ASP.NET page by viewsource from browser. There you can find _VIEWSTATE kind of hidden field. ViewState increases the size of the page because page and page control value store in it.

What is ViewState when ViewState is available?

View State is the method to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back.

Where does ViewState value is stored?

By default, view state data is stored in the page in a hidden field and is encoded using base64 encoding. In addition, a hash of the view state data is created from the data by using a machine authentication code (MAC) key.


6 Answers

This would depend on your end-users. For a internal application where the size of the page is not an important criteria, I would not worry too much about it.
Viewstate is not a problem in itself, it is a problem when it starts slowing down your application because it sends this viewstate back and forth between your client and your server.

You have to consider that the viewstate is sent to the user to be rendered in the source of the page, but it will also be sent back to your server to keep the state of this page, and it will be loaded in memory.

If your end users have a slow internet connection, the bigger the page is , the slower and the more painfull it will be for them.

If your hosting provider is billing you depending on the data transfered, you might want to reduce it as much as possible too. especially if you have a lot of users...

Also consider the memory available on your server as the viewstate is loaded in the RAM for each request, for each user.

like image 72
Stéphane Avatar answered Sep 28 '22 17:09

Stéphane


You need to make it smaller than a Borg Cube:

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

ViewState will add your web app's distinctiveness to it's own. Performance is futile.

like image 26
Greg Avatar answered Sep 28 '22 16:09

Greg


I think it basically depend on what you have to achieve, and how much you are using it for "intentional" purposes. Anyway there are ways to measure, decode and optimize it:

http://jagbarcelo.blogspot.com/2009/03/viewstate-size-minimization.html

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5229520.html

http://scottonwriting.net/sowblog/posts/4409.aspx

like image 37
mamoo Avatar answered Sep 28 '22 18:09

mamoo


It depends.....If you have 1 user then size is not as important compared to if you have a million users. You also need to know how much RAM you have and if you are running out of RAM

like image 33
SQLMenace Avatar answered Sep 28 '22 18:09

SQLMenace


I'm not sure that there is an "acceptable size" for a viewstate - it just depends on the size and complexity of your page. I know that its easy for it to become bloated and much bigger than it needs to be - a couple weeks ago we decoded our viewstate and found we could reduce it by about 40% on some of our larger pages.

Your viewstate should be as big as it needs to be. Just make sure to keep an eye on it to make sure it isn't bloating up with information that is completely unnecessary to a postback.

like image 39
Jarrod Nettles Avatar answered Sep 28 '22 17:09

Jarrod Nettles


It depends on a lot of factors. A page with a lot of controls & content will have a lot more viewstate. What's acceptable, depends on the bandwidth limitations you have. If it's an internal company application and doesn't have a lot of users, a bigger viewstate(200-500k) may be acceptable. If it's on the web or a lot of users will be on it, you should limit the viewstate.

To limit viewstate, look at ways to improve your UI so it's not as complicated. Modal pop ups such as the Telerik RadWindow to are a good way to move some controls out to another page, while preserving the interaction between the pages.

On complicated pages, Tabs are also a good way to improve UI..each Tab can be it's own page.

like image 38
Ed B Avatar answered Sep 28 '22 16:09

Ed B