即使使用EnableViewstate ="false",也不会禁用视图状态. [英] View state not being disabled eventhough using EnableViewstate ="false"

查看:60
本文介绍了即使使用EnableViewstate ="false",也不会禁用视图状态.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" EnableEventValidation ="false" CodeFile="ViewState1.aspx.cs" Inherits="ViewState1" %>


即使使用按钮控件将页面发布到服务器,文本框的值仍然保留.


The value of textbox is still retained eventhough the page is posted to server using button control.

推荐答案

好吧,这是一个非常常见且非常有效的问题.

我发表了一篇文章初学者查看状态指南 [关于viewstate的一个愚蠢的问题. Pin [ ^ ]您可以在此处查看我的答案.
这是详细信息.
对于答案,首先您需要知道在ASP.NET Page life cycleViewState期间实际发生了什么.
在ASP.Net页面生命周期中,两个事件与视图状态"相关.
1. Load View State :正在为控件加载视图状态数据的位置,并且发生在Page_Load之前.

2. Save View State :控制数据存储在Page_Render之前的隐藏字段中.
现在,如果为控件禁用ViewState ,它应该存储视图状态数据,但是,在Textbox中,您说的是,在禁用视图状态之后,控件将保留数据在postback之后,
这是把戏,
在页面生命周期中还会触发另一个事件,即加载回发数据微笑". :)
实现IPostBackEventHandler 的ASP.NET控件将从相应的postback 数据中加载其值.
该值不是从视图状态中读取,而是从回发中读取,对于实现IPostBackEventHandler
的控件而言,这是正确的 而TextBox 就是这样一种控件Wink | ;)

我的一位朋友Brij在此为什么文本框上有一篇不错的文章即使视图状态设置为关闭,也可以在回发期间保留数据 [
Well, this very common and a very valid question.

I published one article, Beginner''s Guide To View State [^] few years back, and in the discussion forum I have asked the same question. A silly question about viewstate.!!!!! Pin[^] You can check out my answer there.
Here is the details.
For the answer, first of all you need to know what actually happened during ASP.NET Page life cycle and ViewState.
In the ASP.Net page life cycle, two events related with View State.
1. Load View State : Where view state data is loading for the control and which happened before Page_Load.

2. Save View State : Where control data store in a hidden field before the Page_Render.

Now, If you disable the ViewState for the control it should store the view state data but, you are saying in Textbox, after you disabled the view state , control holds the data after postback,
Here is the Trick,
There is another event fired during Page Life Cycle, which is, Load PostBack Data Smile | :)
ASP.NET controls which implement IPostBackEventHandler will load its value from the appropriate postback data.
This value is not read from view state but from Postback From and this is true for those control which implements the IPostBackEventHandler
and TextBox is one such control Wink | ;)

One of my friend Brij, has a nice article on this Why textbox persists data during postback even if View State set to off[^]

Hope this clears your doubts and This will helps you.


答案是实现IPostBackEventHandler的控件,如TextboxCheckbox等,即使禁用了该控件也将保留状态. viewstate.原因是在LoadPostbackData 阶段,这些控件将从回发"表单获取状态信息.

但是未实现IPostBackEventHandler 的标签之类的控件将不会从回传的数据中获取任何状态信息,因此完全依赖于viewstate来维持状态.

阅读本文,您将有所了解

为什么即使在View State设置为off的情况下,文本框在回发期间仍保持数据 [ ^ ]

ViewState和Postback [
The answer is Controls which implements IPostBackEventHandler like Textbox, Checkbox, etc. will retain the state even after disabling the viewstate. The reason is during the LoadPostbackData stage, these controls will get state information from Posted back form.

But controls like label which do not implement IPostBackEventHandler will not get any state information from posted back data and hence depend entirely on viewstate to maintain the state.

Read this article you will get some idea

Why textbox persists data during postback even if View State set to off[^]

ViewState and Postback[^]


这篇关于即使使用EnableViewstate ="false",也不会禁用视图状态.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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