ViewState的使用

原创 2006年05月28日 23:16:00

禁用控件的ViewState,设置控件的EnableViewState="False"即可;禁用Form的ViewState:<%@ Page EnableViewState="False" %>;设置ViewState的值:ViewState( "SomeItem" ) = "Some Value";ViewState是区分大小写的,比如Response.Write( ViewState( "Count" ) )和Response.Write( ViewState( "count" ) )是不一样的。

By default, almost all ASP.NET controls retain the values of their properties between form posts. For example, if you assign text to a Label control and submit the form, when the page is rendered again, the contents of the Label control are preserved.

The magic of view state is that it does not depend on any special server or browser properties. In particular, it does not depend on cookies, session variables, or application variables. View state is implemented with a hidden form field called VIEWSTATE that is automatically created in every Web Forms Page.

Disabling View State:for example, uses the EnableViewState property to disable view state for a Label control. When the page is first loaded, a message is assigned to the Label control and the message is displayed. If you click the button, however, and reload the page, the text disappears from the label.Instead of disabling view state control by control, you also can disable view state for the whole page. You should do so when you are not taking advantage of view state and the controls in a page contain a lot of data. To disable view state for an entire page, modify the EnableViewState attribute of the Page directive.:<%@ Page EnableViewState="False" %>

Adding Values to View State :To add a value to the state bag, use a statement such as the following:ViewState( "SomeItem" ) = "Some Value"。This statement adds a new item to the state bag class named SomeItem with the value Some Value.

ViewState is case-sensitive. The following two statements are not equivalent:

 
Response.Write( ViewState( "Count" ) )

Response.Write( ViewState( "count" ) )



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

ViewState EnableViewState 禁用与使用心得

每个web控件都有个ViewState值,如果一个页面有太多的web控件而不禁用他们的viewstate值的话,会让页面速度大大降低。那么哪些控件的 EnableViewState="false...

使用APPlication,Session,Cookie和ViewState等对象保存信息的区别是什么?

在ASP.NET中,有很多种保存信息的对象.例如:APPlication,Session,Cookie,ViewState和Cache等,那么它们有什么区别呢?每一种对象应用的环境是什么?     ...

ViewState EnableViewState 禁用与使用心得

来自: http://hi.baidu.com/%B1%F9%BB%F0%D5%BD%B5%D8/blog/item/07c7a244936677026b63e5f0.html 每个web控...

使用PHP的CURL模拟POST采集开了viewstate的asp.net网页数据

/**     QQ群:223494678     函数:模拟post得到所有分页的页面信息     参数:         string $EVENTARGUMENT   ...

关于Asp.net中static与ViewState使用的探讨

摘 要: 利用asp.net 开发基于B/S模式的应用系统,经常会遇到同一页面类的各函数 成员之间、同一会话各页面之间、不同机器各用户页面之间的传值问题,即要解决数据共享 的问题。这可以选择使用App...

C#强化系列文章一:ViewState使用兼谈序列化 [转]

在解决session过期的问题时遇到了序列化的问题,今天开始学习一下。  ViewState的使用比较简单,一两句话就可以了。赋值:ViewState[key] = value;取值:value = ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)