当控件变为Enable = False时,ASP.Net ViewState不起作用 [英] ASP.Net ViewState doesn't work when Control become Enable=False

查看:89
本文介绍了当控件变为Enable = False时,ASP.Net ViewState不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当控件确实包含值但将其设置为.Enable = False时,所有控件都被禁用(没关系),但是为什么ViewState在下一次发回时不保留数据?如果我没有修改其Enable状态而得到UserControl,则ViewState在回发之间工作。

Why when a control does contain value but it's set to .Enable=False that all controls become disable (that's ok) but why that the ViewState doesn't retain the data on the next post back? If I get the UserControl without modifing its Enable state, the ViewState work between post back.

我们如何禁用所有控件变为禁用状态的UserControl(这部分工作)但是所有人都保持使用ViewState(这不起作用)吗?

How can we disable a UserControl that all its control become disable (this part work) but all of them KEEP use the ViewState (this doesn't work)?

1)在aspx.cs中,单击按钮编辑:

1)In the aspx.cs click button

myControl.Enabled = false;
//This produce to have all controls in myControl to be disabled.

2)在asp.cs中:点击保存以退出编辑状态:

2)In the asp.cs: click Save to leave the EDIT state:

myControl.Enabled = true;
//This produce that all controls inside myControl are blank : no viewstate!

其他回发工程是因为我们没有将myControl.Enable设置为false。

Other postback works because we do not put myControl.Enable to false.

推荐答案

指定 .Enable = False 就像是服务器端禁用,而不是客户端禁用。这是出于安全性目的,因此即使用户使用某些客户端欺骗手段来重新启用输入元素,您也可以真正禁用它。如果要执行客户端禁用,则需要为此使用脚本,或者使用 readonly 属性。

Specifying .Enable=False is like a server-side disable, NOT a client-side disable. This is for security purposes so you can truly disable an input element even if the user uses some client-side trickery to "re-enable" it. If you want to perform a client-side disabling, you'll need to use script for that, or perhaps use a readonly attribute.

这篇关于当控件变为Enable = False时,ASP.Net ViewState不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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