我该如何为特定的控制禁用视图状态? [英] How do I disable viewstate for a specific control?

查看:132
本文介绍了我该如何为特定的控制禁用视图状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:TextBox ID="TextBox1" runat="server" EnableViewState="false" />
<asp:Button ID="Button1" runat="server" Text="Button" />

我已经EnableViewState属性设置为false,但是当我点击按钮,在文本框中的值回发后仍然存在。为什么坚持价值?

I have set the EnableViewState property to false, but when I click on the button the value in the textbox persists after the postback. Why does the value persist?

推荐答案

有一个看的了解ASP.NET视图状态。在页面生命周期,有一个装载数据后阶段将从表的数据填充控制值。

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.

这篇关于我该如何为特定的控制禁用视图状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆