If you think your website is running slowly and you need to improve performance by 150% in short time. This may help you a lot.
ASP.NET ViewState is a great mechanism that simplifies the life of ASP.NET developers. But, as everybody knows, the .NET Framework saves the ViewState data as a hidden field on your ASPX page. If your page has only a few controls, this is not a problem. But, if your page has some
Panel
s and/or some DataGrid
s, with the technique demonstrated on this article, you could reduce dramatically the load time of the page.We will start our analysis thinking where the Framework needs to work with the data saved on the ViewState hidden field. The answer is: only on the server side. The system doesn't need to work with the ViewState data on the client side, so, if we start to save this data on the server instead of carrying all this from the server to the client and from the client to the server again, we will save a lot of time while loading our documents. You probably won't note the difference while loading the page on the same computer that the application is installed, but, test it using a dial-up connection and you will see what happens. You could also see the size of the source code generated with and without this technique.
You can store ViewState in Cache, Session or Database. I have attached sample code for implementing this idea in your application.
All that you need to do is add a reference to the class that accompanies this example and inherit your "code-behind files" from it instead of the
System.Web.UI.Page
, and add the Config information to your Web.Config.For more help you can visit here and also here is some good view state information!
If you are storing ViewState in Session and if you are continuously receiving the following error even after you set ViewStateTableSize to 200, you should store your ViewState to Database, because after that increasing it more would not help more in improving performance:
“VIEWStateKey not Found. Consider increasing the ViewStateTableSize parameter on Web.Config file.”