简体   繁体   English

如何分析控件对Viewstate的使用

[英]How to profile use of Viewstate by controls

I have a couple of pages that are bulky due to the viewstate. 由于viewstate,我的页面有些大。 I have following question: 我有以下问题:

  • is there any tool that can track viewstate of individual control on page and tell me which control is taking maxm viewstate 是否有任何工具可以跟踪页面上单个控件的视图状态并告诉我哪个控件正在使用maxm viewstate

  • also can i know which controls viewstate is not being used and disable it? 我还能知道哪些控件未使用viewstate并将其禁用吗?

There are some Viewstate Utilities listed here http://blogs.msdn.com/rextang/archive/2007/05/25/2868250.aspx . http://blogs.msdn.com/rextang/archive/2007/05/25/2868250.aspx此处列出了一些Viewstate实用程序。 I always store Viewstate in the database rather than send it back and forth over the internet. 我总是将Viewstate存储在数据库中,而不是通过Internet来回发送它。 Example Code here http://www.componentworkshop.com/blog/2009/06/27/advanced-net-storing-viewstate-in-a-database 此处的示例代码http://www.componentworkshop.com/blog/2009/06/27/advanced-net-storing-viewstate-in-a-database

You can turn on trace on the page and that should show how much viewstate is used for each control. 您可以在页面上打开跟踪,并且应该显示每个控件使用了多少viewstate。

I have no good answer to your second question, but one rule of thumb I use when i develop webforms is that i set EnableViewState=false immediately after I've created an Ascx. 对于第二个问题,我没有好的答案,但是在开发Web表单时使用的一条经验法则是,在创建Ascx之后,我立即设置了EnableViewState = false。

That way I can turn it on when I actually need it and not wonder if my databound controls uses alot of viewstate. 这样,我可以在实际需要时将其打开,而不用担心我的数据绑定控件是否使用了大量的viewstate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM