问题登记。 ASP.NET 视图状态

发布于 2024-11-25 04:38:18 字数 364 浏览 4 评论 0原文

我一直在阅读这篇优秀的文章 http://msdn.microsoft.com/ en-us/library/ms972976.aspx 表示 ViewState 不负责表单字段在回发之间保留其值。那么表单字段值永远不会存储在 ViewState 中吗?

编辑:我的意思是表单字段是 ASP.NET 控件,如 TextBox、Dropdownlist 等。

编辑:如果用户在 ASP.NET 文本框中输入一个值并提交表单,新页面仍然具有我正在考虑的具有该值的文本框这是因为 ViewState 但文章说事实并非如此!

I've been going through this excellent article http://msdn.microsoft.com/en-us/library/ms972976.aspx that says ViewState is not responsible for form fields to retain their values between postbacks. So form fields values are never stored in ViewState?

EDITED: What I mean form fields are ASP.NET controls like TextBox, Dropdownlist etc.

EDITED: If an user enters a value in an ASP.NET textbox and submit the form, the new page still has the textbox with that value I was thinking this is because of ViewState but the article says it's not so!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

榕城若虚 2024-12-02 04:38:18

正如您所说,表单值不存储在视图状态中。 (例如)TextBox 控件的文本在两次回发之间保留的原因是它实现了 IPostBackDataHandler-契约并自动将 Request.Form-collection 中的键映射到控件的相应属性。这两种机制经常被混淆。

请参阅http://www.mikesdotnetting.com/Article/ 65/ViewState-form-fields-labels-and-Javascript 以获得很好的解释。

As you say, form values are NOT stored in the viewstate. The reason that (for example) the text of a TextBox control is retained between two postbacks is because it implements the IPostBackDataHandler-contract and automatically maps the keys in the Request.Form-collection to the appropriate properties of the control. These two mechanisms are often confused.

See http://www.mikesdotnetting.com/Article/65/ViewState-form-fields-labels-and-Javascript for a good explanation.

北方的巷 2024-12-02 04:38:18

文本字段不会在 ViewState 中携带其值,因为它们的值是通过 HTTP POST 显式发送的(请参阅 Request.Form),并在 Page_Load 之前恢复到控件。

DropDownList 确实使用 ViewState 来存储其内容。

Text fields don't carry their value in ViewState because their value is explicitly sent through the HTTP POST (See Request.Form) and restored to the control before Page_Load.

DropDownLists do use ViewState to store their contents.

月光色 2024-12-02 04:38:18

只有 Asp.Net Control 才会存储在 ViewState 中。没有 html 字段。

所以

<asp:TextBox id="tb1" runat="server" />

会起作用,

<input type="text" id="tb1" />

不会起作用。

only Asp.Net Control will stored in the ViewState. No html fields.

So

<asp:TextBox id="tb1" runat="server" />

will work and

<input type="text" id="tb1" />

will not work.

森林散布 2024-12-02 04:38:18

那么表单字段值永远不会存储在 ViewState 中?

正如 dknaack 所说:否

但是您可能还想看看 ControlState 因为 ViewState 可以被禁用。

So form fields values are never stored in ViewState?

As stated by dknaack: No

But you may also want to have a look at ControlState since ViewState can be disabled.

水溶 2024-12-02 04:38:18

viewstate 的观点是跟踪 web 控件中的“变化”。作为开发人员,您有责任确保每次页面加载时重新创建控件的“初始”状态。然后,asp .net 机制确定回发场景期间发生的更改,以决定应在服务器端触发哪些事件。

要了解 ASP .Net 回发机制的工作原理以及 Viewstate 的适用范围,请查看我最初在 SO 上提出的这个问题;

回发是如何工作的?

The point of viewstate is to track the "change" in your webcontrols. It's your responsibility as a developer to ensure that the "initial" state of your controls is recreated each page load. Then the asp .net mechanism determines the change that occurred during a postback scenario to decide which events should be fired on the server side.

For an overview of how the ASP .Net postback mechanism works and where Viewstate fits in have a look at this question I originally asked on SO;

How does Postback Work?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文