ViewstateEnabled =假 [英] ViewstateEnabled=False

查看:82
本文介绍了ViewstateEnabled =假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



网页中有两个文本框和一个按钮控件.我们将两个文本框的设置都更改为ViewstateEnabled = False.在按钮单击事件中,我们编写了代码以在TextBox2中显示TextBox1值.

该值正在TextBox2中显示,即使两个文本框ViewstateEnabled = False,它也都不会从TextBox1中删除.是什么原因?请回答.

预先感谢

Hi,

There are two textboxes and one button control in a Web page. We change the setting as ViewstateEnabled=False to both the textboxes. In button click event we have written the code to display TextBox1 value in TextBox2.

The value is displaying in TextBox2 as well as it didn''t remove from TextBox1 also even if both the textboxes ViewstateEnabled=False. What is the reason? Please answer.

Thanks in advance

推荐答案

要获得答案,首先您需要了解ASP.NET Page生命周期中实际发生了什么和ViewState.
在ASP.Net页面生命周期中,有两个与View State相关的事件.
1. Load View State :其中正在加载控件的视图状态数据,并且发生在Page_Load.

之前. 2. Save View State :控件数据存储在Page_Render之前的隐藏字段中.

现在,如果禁用控件的ViewState ,则它应该存储视图状态数据,但是,在Textbox中,禁用视图状态后,控件将保留回发后的数据,
这是技巧,
在页面生命周期中触发了另一个事件,即Load PostBack Data: )实现IPostBackEventHandler 的ASP.NET控件将从适当的回发数据中加载其值.
该值不是从视图状态读取的,而是从Postback From和t 读取的.实现IPostBackEventHandler
TextBox 的控件就是这样一种控件Wink

Ho pe这样可以清除您的疑虑,这将对您有所帮助.

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 :)
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

Hope this clears your doubts and This will helps you.


在问所有这些问题之前,请先购买ASP.NET上的基础书籍并阅读.

Please buy a basic book on ASP.NET and read it before asking all these questions.


这篇关于ViewstateEnabled =假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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