Which controls have ViewState maintained?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:32:11

There are 3 types of controls, the standard HTML elements like , HTML server controls which have the runat=server tag added, and full web controls. Only the web controls have viewstate maintained.

When we were having problems with viewstate I started using the Viewstate helper software from Binary Fortress http://www.binaryfortress.com/aspnet-viewstate-helper/

It gives you a real insight into what's going on - as well as helping with viewstate related performance issues you can decode the viewstate with one click and see what is actually in there - so you get to understand what controls are using viewstate and which aren't, and exactly what they are storing in there.

Also, something nobody else has mentioned is ControlState. This came along with ASP.NET 2 and the theory is that the important stuff that is necesssary for a control to function goes in the control state, and the data etc in the viewstate, so you can switch off the viewstate and bind the data to your control on every postback and the control still basically works using controlstate. I say "theory" because in practice the implementation seems patchy. When you look into the dropdownlist code using reflector for example this isn't properly implemented. This may have changed with later releases of the framework, I'm not sure. Lots of info on controlstate out there if you search for it, I just thought I'd mention it.

afaik no, that HTML controls are not designed to maintain anything in the viewstate, if you care about it, take the webcontrols.

Jon Smock

Anything you put on your page's view and add the runat="server" will have the viewstate maintained.

As for dynamically added controls, it depends on when and how you add the control to the control tree. Check out the accepted answer to this question, but also check out my question here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!