How do I disable viewstate for a specific control?

好久不见. 提交于 2019-12-01 12:17:00

Have a look at Understanding ASP.NET View State. In the page lifecycle, there is a Load Post Data stage that will populate your control values from the form data.

View State can be very confusing, specifically why you need it if controls are populated with form data on post back. The Role of View State from the same link above does a decent job of explaining why it's useful.

To summarize: View State is not required for user input. View State is used to store programmatic changes to a pages state that occur. A simple example is when a non-submit button is clicked and the handler alters a label's text. That change should be stored in the View State so it is persisted across additional post backs.

The controls that accept input can have their state restored by using the data posted to the server. They needn't be stored in the ViewState. In a way these are not the old values these are the NEW values that the user submitted (despite the fact that he may not have changed them).

Explanation

The simplest way is to set each time the Text property to String.Empty.

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