Asp.net web Control Enable 属性设置
2014-04-05 12:47
351 查看
最近手上有一个很简单的一个小项目,需要查看编辑的历史记录,先前设计的时候把数据都save 到DB了,现在时间紧迫 就不在画新的UI,而是采用以前的edit页面 来显示数据,这里就需要把页面上所有的control都设置为disable。而一般的control是没有Enable属性,只有WebControl才有这个属性。所以默认我们会检查当前的control是否是webcontrol,如果是直接设置enable属性,如果不是我们可以通过反射来查找,这里测试了以下,满足我页面的需求,主要代码实现如下:
测试结果如图:
public static class ExtendClass { public static void SetEnable(this Control ctrl, bool value, Func<Control, bool> fun) { bool ret = true; if (fun != null) { ret = fun(ctrl); } if (ret) { if (typeof(WebControl).IsAssignableFrom(ctrl.GetType())) { ((WebControl)ctrl).Enabled = value; } else { PropertyInfo property = ctrl.GetType().GetProperty("Enabled"); if (property != null) { property.SetValue(ctrl, value, null); } } } foreach (Control item in ctrl.Controls) { SetEnable(item, value, fun); } } }
测试结果如图:
相关文章推荐
- Asp.net web Control Enable 属性设置
- ASP.NET的Web.Config 节点的属性设置说明
- ASP.NET的Web.Config 节点的属性设置说明
- asp.net中控件的enableviewstate属性 的设置
- 利用 HttpModule,基于输出,统一控制、干预、处理(例如: 过滤关键字、AntiXSS) ASP.Net WebForm Control 展现属性的方案原型
- [ASP.NET]为什么CustomValidator验证控件在验证DropdownList的时候不能设置ControlToValidate属性
- ASP.NET 的 WebControl.Attributes 属性
- WCF项目问题2-无法激活服务,因为它需要 ASP.NET 兼容性。没有未此应用程序启用 ASP.NET 兼容性。请在 web.config 中启用 ASP.NET 兼容性,或将 AspNetCompatibilityRequirementsAttribute.AspNetCompatibilityRequirementsMode 属性设置为 Required 以外的值。
- Asp.net Web控件自定义类属性(经验篇)
- Web Control开发随笔(1):ASP.NET 页面的生命周期
- asp.net设置元素css的属性
- asp.net中Web.config文件各属性详解
- ASP.net中同时设置控件的多个属性,以及设置背景透明色。
- ASP.Net在web.config中设置上传文件的大小方法
- SSRS:ASP.NET中引用报表远程认证之ReportServerCredentials属性的设置
- Web Control开发随笔(2):ASP.NET 控件生命周期
- 控件发布:FCKeditor ASP.NET 2.0 WebControl
- ASP.Net在web.config中设置上传文件的大小方法
- Web Server Controls->ASP.NET ListBox Control