什么是ASP.NET中的ViewState? [英] What is the ViewState in ASP.NET?
问题描述
有人可以尽可能简洁地解释ViewState(在ASP.NET中)吗?
Can anybody explain ViewState(in ASP.NET) as succintly as possible?
推荐答案
ViewState
是一种允许在页面回发之间保留状态值的机制.
ViewState
is the mechanism that allows state values to be preserved across page postbacks.
网络是无状态的.但是在ASP.NET中,页面的状态会自动保留在页面本身中.这是使用ViewState完成的.在ViewState中,值以64为基数编码,并保存在隐藏的控件中.
The web is stateless. But in ASP.NET, the state of a page is maintained in the page itself automatically. This is done Using ViewState. In ViewState the values are base 64 encoded and saved in hidden controls.
当您查看使用ViewState的页面的页面源(在浏览器中)时,您可能会看到此隐藏的ViewState输入,看起来像这样:
When you view the page source (in your browser) of a page the uses ViewState, you may see this hidden ViewState input which will look something like this:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM1ODM3Nj......." />
此单个隐藏字段包含所有页面控件的所有viewstate值.
This single hidden field contains all the viewstate values for all the page controls.
因为(默认情况下)ViewState被发送到客户端浏览器,然后以页面上的隐藏输入控件的形式返回到服务器,所以在ViewState中存储大量数据可能会增加页面大小并影响您的页面效果.
Because ViewState is (by default) sent to the client browser and then returned to the server in the form of a hidden input control on your page, storing a significant amount of data in ViewState can increase your page size and can affect your page performance.
要为控件禁用ViewState,可以将 EnableViewState
属性设置为false.
To disable ViewState for a control, you can set the EnableViewState
property to false.
这篇关于什么是ASP.NET中的ViewState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!