Is it possible to disable viewstate for a specific type of controls in web.config?
I know I can disable viewstate for all pages using <pages enableViewState="false">, but what if I wanted to target just all Label controls?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One of the crud way, could be to iterate all controls recursively in the page and disable the view-state for label controls – obvious issue is that you need to do this early in page cycle and then in such case, you may miss the dynamically added controls.
The more elegant solution would be to create a custom control inheriting from say label control and disable the view-state (say in the constructor) – for example
(Mind you that in a robust implementation, you should ensure that view-state is disabled before it gets saved.)
Now, you can use ASP.NET tag mapping feature to map all label controls to your label controls from web.config.