Hi
Does ViewState affect performance. What is the ideal size of a ViewState. How can you compress a viewstate ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted May 9, 2012, 2:53 AM
View state is an unnecessary overhead for pages that do not need it. As the view state grows larger, it affects performance in the following ways:
pls refer this url
http://www.guidanceshare.com/wiki/ASP.NET_2.0_Performance_Guidelines_-_View_State
thanks.
If this post is useful then mark it as "Accepted Answer"
Jignesh TrivediPosted May 9, 2012, 12:00 AM
view state is store on page with HTML, so if you have large View state data then definately that affect performance.
Size of View state is generally in byte or in KB.
Ideally View state is already in compression mode.
so I think you can use IIS compression.
hope this help.
SenthilkumarPosted May 8, 2012, 11:44 PM
Does ViewState affect performance ?
Yes. It needs to load the data across the post backs and lot of loads to the server as well as it needs to render into the web page. The size of the view state will be depends on the data and it will be encrypted and descrypted every time when submit to the server. It will have the encrypted data format in the hidden control. The size of the page will be more. It will take time to render on the web page.
What is the ideal size of a ViewState ?
To maximize performance, each page should be judged on whether it needs ViewState information. If no ViewState is needed in the page or any of its controls, set the EnableViewState property of the page or control to false. Also, remove the runat="Server" attribute from the form tag. If this tag isn't removed, the page itself passes on about 20 bytes of information to the ViewState.
If ViewState is needed, make sure it is enabled only for controls that are really going to use it. Some controls, such as Label and TextBox, do not have a large ViewState footprint. But DataGrids and DataRepeaters store all of their data in ViewState by default, making the page's output potentially very large.
If you want to use one of these larger footprint controls, you can reduce its size by setting the EnableViewState property to false. This will force the DataGrid to go to the datasource for its data with each request, which of course impacts whatever datasource you're using. But it will greatly reduce the size of the HTML stream sent to the client.
For more info:
http://www.4guysfromrolla.com/articles/091510-1.aspx
How can you compress a viewstate?
The compression functionality in GZipStream is exposed as a stream. In the code displayed below, we will create a class called ViewStateCompressor that contains two methods :
Compress(byte[] array) - Accepts a decompressed bytearray, compresses it and returns a compressed bytearray.
Decompress(byte[] array) – Accepts compressed bytearray, decompresses it and returns a decompressed bytearray.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=67
http://www.codeproject.com/Articles/14733/ViewState-Compression
Drawbacks:
- Increase the page payload (when you have grid with many rows then every thing has to be loaded and retain again with serialize and deserilize)
- Additional overhead while serialize and deserialize.
- Increase the memory allocation on the server.
-It can be tempered by the hackers if they know the format.
Satyapriya NayakPosted May 8, 2012, 9:57 PM
Viewstate stores the state of controls in HTML hidden fields. At times, this information can grow in size. This does affect the overall responsiveness of the page, thereby affecting performance. The ideal size of a viewstate should be not more than 25-30% of the page size.
Viewstate can be compressed to almost 50% of its size. .NET also provides the GZipStream or DeflateStream to compress viewstate.
Simillar threadhttp://www.c-sharpcorner.com/Forums/Thread/168973/viewstate.aspx
Please refer the below links also
http://www.c-sharpcorner.com/UploadFile/051e29/introducing-viewstate-in-Asp-Net/
http://www.w3schools.com/aspnet/aspnet_viewstate.asp
http://asp.net-tutorials.com/state/viewstate/
Thanks