时间:2016-02-15 23:43 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net 简单实现禁用或启用页面中的某一类型的控件】,下面是详细的讲解!
asp.net 简单实现禁用或启用页面中的某一类型的控件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace DotNet.Common.Util
{
/// <summary>
/// 控件枚举,我们在禁用或启用时,就是根据这个枚举来匹配合适的项
/// </summary>
public enum ControlNameEnum
{
Panel=0, //容器 这个比较常用
TextBox=1,
Button=2, //这个也比较常用 比如 按钮提交后的禁用,返回结果后启用
CheckBox=3,
ListControl=4,
All=100 //所有
}
public static class ControlHelper
{
#region 同时禁用或者启用页面的某些控件
/// <summary>
/// 设置是否启用控件
/// </summary>
/// <param name="control"></param>
/// <param name="controlName"></param>
/// <param name="isEnable"></param>
public static void SetControlsEnabled(Control control, ControlNameEnum controlName, bool isEnabled)
{
foreach (Control item in control.Controls)
{
//Panel
if (item is Panel && (controlName==ControlNameEnum.Panel || controlName==ControlNameEnum.All))
{
((Panel)item).Enabled=isEnabled;
}
//TextBox,HtmlTextBox
if (controlName==ControlNameEnum.TextBox || controlName==ControlNameEnum.All)
{
if (item is TextBox)
{
((TextBox)(item)).Enabled=isEnabled;
}
else if (item is HtmlInputText)
{
((HtmlInputText)item).Disabled=isEnabled;
}
else if (item is HtmlTextArea)
{
((HtmlTextArea)(item)).Disabled=isEnabled;
}
}
//Buttons
if (item is Button && (controlName==ControlNameEnum.Button || controlName==ControlNameEnum.All))
{
if (item is Button)
{
((Button)(item)).Enabled=isEnabled;
}
else if (item is HtmlInputButton)
{
((HtmlInputButton)(item)).Disabled=!isEnabled;
}
else if (item is ImageButton)
{
((ImageButton)(item)).Enabled=isEnabled;
}
else if (item is LinkButton)
{
((LinkButton)(item)).Enabled=isEnabled;
}
}
//CheckBox
if (controlName==ControlNameEnum.CheckBox || controlName==ControlNameEnum.All)
{
if (item is CheckBox)
{
((CheckBox)(item)).Enabled=isEnabled;
}
else if (item is HtmlInputCheckBox)
{
((HtmlInputCheckBox)(item)).Disabled=!isEnabled;
}
}
//List Controls
if (controlName==ControlNameEnum.ListControl || controlName==ControlNameEnum.All)
{
if (item is DropDownList)
{
((DropDownList)(item)).Enabled=isEnabled;
}
else if (item is RadioButtonList)
{
((RadioButtonList)(item)).Enabled=isEnabled;
}
else if (item is CheckBoxList)
{
((CheckBoxList)(item)).Enabled=isEnabled;
}
else if (item is ListBox)
{
((ListBox)(item)).Enabled=isEnabled;
}
else if (item is HtmlSelect)
{
((HtmlSelect)(item)).Disabled=!isEnabled;
}
}
//如果项目还有子控件,递归调用该函数
if (item.Controls.Count > 0)
{
SetControlsEnabled(item, controlName, isEnabled);
}
}
}
#endregion
}
}
关于asp.net 简单实现禁用或启用页面中的某一类型的控件的用户互动如下:
相关问题:asp.net编程,当我点击gridview控件时,ie状态栏上报...
答:最近也在搞.NET的,也是用了GridView控件,用的蛮好啊~~ 你的问题能说的具体点么? 邮科院校区成绩查询系统 返回 public partial class StuSearch : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected ... >>详细
相关问题:据说ASP.NET可以在页面关闭视图,在某个控件上打开...
答:最好的办法就是不用服务器控件 ,一切迎刃而解 >>详细
相关问题:我要使用ASP.NET建立一个网站,功能中包含 会议直...
答:本地搭建流媒体直播系统,要用2003或者2008的流媒体服务器。 >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 【asp】asp.net开发中常见公共捕获异常方式总结(
- 【Visual】分享Visual Studio原生开发的10个调试
- 【全局】.net全局定时定期执行某些操作在Global.a
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
