禁用页面控件

news/2024/7/4 0:53:48 标签: textbox, button, asp.net, c, 服务器, class
class="tags" href="/tags/C.html" title=c>cle class="tags" href="/tags/C.html" title=c>class="baidu_pl">
class="tags" href="/tags/C.html" title=c>cle_class="tags" href="/tags/C.html" title=c>content" class="tags" href="/tags/C.html" title=c>class="articlass="tags" href="/tags/C.html" title=c>cle_class="tags" href="/tags/C.html" title=c>content class="tags" href="/tags/C.html" title=c>clearfix">
class="tags" href="/tags/C.html" title=c>content_views" class="tags" href="/tags/C.html" title=c>class="htmledit_views">  

publiclass="tags" href="/tags/C.html" title=c>c staticlass="tags" href="/tags/C.html" title=c>c class="tags" href="/tags/C.html" title=c>class ControlHelper
    {
        #region 同时禁用或者启用页面的某些控件
        /// <summary>
        /// 设置是否启用控件
        /// </summary>
        /// <param name="class="tags" href="/tags/C.html" title=c>control"></param>
        /// <param name="class="tags" href="/tags/C.html" title=c>controlName"></param>
        /// <param name="isEnable"></param>
        publiclass="tags" href="/tags/C.html" title=c>c staticlass="tags" href="/tags/C.html" title=c>c void SetControlsEnabled(Control class="tags" href="/tags/C.html" title=c>control, ControlNameEnum class="tags" href="/tags/C.html" title=c>controlName, bool isEnabled)
        {
            foreaclass="tags" href="/tags/C.html" title=c>ch (Control item in class="tags" href="/tags/C.html" title=c>control.Controls)
            {
                /* 我们仅仅考虑几种常用的class="tags" href="/tags/C.html" title=c>class="tags" href="/tags/ASP.NET.html" title=asp.net>asp.netclass="tags" href="/tags/FuWuQi.html" title=服务器>服务器控件和html控件 */
                //Panel
                if (item is Panel && (class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.Panel || class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.All))
                {
                    ((Panel)item).Enabled = isEnabled;
                }
                //TextBox,HtmlTextBox
                if (class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.TextBox || class="tags" href="/tags/C.html" title=c>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 && (class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.Button || class="tags" href="/tags/C.html" title=c>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;
                    }
                }
                //Checlass="tags" href="/tags/C.html" title=c>ckBox
                if (class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.Checlass="tags" href="/tags/C.html" title=c>ckBox || class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.All)
                {
                    if (item is Checlass="tags" href="/tags/C.html" title=c>ckBox)
                    {
                        ((Checlass="tags" href="/tags/C.html" title=c>ckBox)(item)).Enabled = isEnabled;
                    }
                    else if (item is HtmlInputCheclass="tags" href="/tags/C.html" title=c>ckBox)
                    {
                        ((HtmlInputCheclass="tags" href="/tags/C.html" title=c>ckBox)(item)).Disabled = !isEnabled;
                    }
                }
                //List Controls
                if (class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.ListControl || class="tags" href="/tags/C.html" title=c>controlName == ControlNameEnum.All)
                {
                    if (item is DropDownList)
                    {
                        ((DropDownList)(item)).Enabled = isEnabled;
                    }
                    else if (item is RadioButtonList)
                    {
                        ((RadioButtonList)(item)).Enabled = isEnabled;
                    }
                    else if (item is Checlass="tags" href="/tags/C.html" title=c>ckBoxList)
                    {
                        ((Checlass="tags" href="/tags/C.html" title=c>ckBoxList)(item)).Enabled = isEnabled;
                    }
                    else if (item is ListBox)
                    {
                        ((ListBox)(item)).Enabled = isEnabled;
                    }
                    else if (item is HtmlSeleclass="tags" href="/tags/C.html" title=c>ct)
                    {
                        ((HtmlSeleclass="tags" href="/tags/C.html" title=c>ct)(item)).Disabled = !isEnabled;
                    }
                }
                //如果项目还有子控件࿰class="tags" href="/tags/C.html" title=c>c;递归调用该函数
                if (item.Controls.Count > 0)
                {
                    SetControlsEnabled(item, class="tags" href="/tags/C.html" title=c>controlName, isEnabled);
                }
            }
        }
    }
    #endregion

 

 


ControlHelper.SetControlsEnabled(this.Page, ControlNameEnum.Panel, false); //Panel禁用
                    ControlHelper.SetControlsEnabled(this.Page, ControlNameEnum.TextBox, false); //TextBox禁用
                    ControlHelper.SetControlsEnabled(this.Page, ControlNameEnum.ListControl, false); //TextBox禁用
                    ControlHelper.SetControlsEnabled(this.Page, ControlNameEnum.All, false); //TextBox禁用

 

 

 


另一种
private void FindControls(ControlColleclass="tags" href="/tags/C.html" title=c>ction class="tags" href="/tags/C.html" title=c>cclass="tags" href="/tags/C.html" title=c>c)
    {
        foreaclass="tags" href="/tags/C.html" title=c>ch (Control class="tags" href="/tags/C.html" title=c>c in class="tags" href="/tags/C.html" title=c>cclass="tags" href="/tags/C.html" title=c>c)
        {
            if (class="tags" href="/tags/C.html" title=c>c.HasControls())
                FindControls(class="tags" href="/tags/C.html" title=c>c.Controls);
            else
            {
                if (class="tags" href="/tags/C.html" title=c>c is System.Web.UI.WebControls.TextBox)
                    (class="tags" href="/tags/C.html" title=c>c as System.Web.UI.WebControls.TextBox).Enabled = false;
                if (class="tags" href="/tags/C.html" title=c>c is DropDownList)
                    (class="tags" href="/tags/C.html" title=c>c as System.Web.UI.WebControls.DropDownList).Enabled = false;
                if (class="tags" href="/tags/C.html" title=c>c is System.Web.UI.WebControls.Label)
                    (class="tags" href="/tags/C.html" title=c>c as System.Web.UI.WebControls.Label).Enabled = false;
                if (class="tags" href="/tags/C.html" title=c>c is System.Web.UI.HtmlControls.HtmlForm)
                    (class="tags" href="/tags/C.html" title=c>c as System.Web.UI.HtmlControls.HtmlForm).Disabled = true;
                if (class="tags" href="/tags/C.html" title=c>c is System.Web.UI.HtmlControls.HtmlInputText)
                    (class="tags" href="/tags/C.html" title=c>c as System.Web.UI.HtmlControls.HtmlInputText).Disabled = true;
            }
        }
    }

 


FindControls(this.form1.Controls);

class="tags" href="/tags/C.html" title=c>cle>

http://www.niftyadmin.cn/n/925568.html

相关文章

Zookeeper 分布式锁原理与实现入门

分布式锁的应用场景 1.为什么需要分布式锁 比如,小型电商网站,下单,生产有一定业务含义的唯一的订单编号 如: 2017-05-16-20-52-33-01 年月日时分秒-序号 订单服务类 调用 订单编号生成类 如果同时有很多人下单… 并发下单,此时订单号能做到唯一吗?? 互联网中这就是…

小知识集锦

2、Int32.Parse(变量) Int32.Parse("常量") 字符型转换 转为32位数字型 3、变量.Length 数字型 取字串长度&#xff1a; 如&#xff1a; string str"中国"; int Len str.Length ; //Len是自定义变量&#xff0c; str是求测的字串的变量名 4、 变量…

maven 中okhttp依赖冲突NoSuchMethodError解决

背景 A 模块是有main入口的spring boot项目,pom引入B模块, B模块引入C模块。 其中,A与B模块parent一致,C模块独立。 此时A与B模块中的okhttp依赖为 com.squareup.okhttp3 ,其版本为3.4.2 C模块则为com-framework-okhttp。打包A模块,出来的lib包中,是com.squareup.okhtt…

你所了解又并不是很了解的并发锁——synchronized

共享资源在多线程下要保证安全,从而引入并发锁,在多进程中,则为分布式锁。 多线程环境里面,假如有一个共享int变量i。如下两个线程都对,i++,那么结果有可能是1,有可能是2 那么此时就可以使用synchronized 关键字。 但是加锁后,并行就变成了串行,降低了效率,那么我们…

Git如何解决本地冲突(纯净版)

第一步、拉取远程最新代码 git fetch -a第二步、切换到源分支 如果本地有源分支 git checkout branch_new如果本地没有源分支 git checkout -b branch_new origin/branch_new第三步、合并代码 此处&#xff0c;不要使用fast-forward容易&#xff0c;覆盖合并 git merge -…

jdk1.8 Jmap pid info- 37103 interned Strings occupying 4038832 bytes ,String intern()方法

Heap Configuration: //堆内存初始化配置MinHeapFreeRatio = 40 //堆最小空闲比率MaxHeapFreeRatio = 70 //堆最大空闲比率MaxHeapSize = 2147483648 (2048.0MB) //堆最大空间NewSize = 715784192 (682.625MB) //堆新生代的默认…

详细年龄 生日倒计时

脚本说明&#xff1a; 把如下代码加入<body>区域中: <SCRIPT LANGUAGE"JavaScript"> <!-- Begin function run() { with (document.agecalc) { dd parseInt(day.selectedIndex) 1; mm parseInt(month.selectedIndex) 1; yy year.value; if (yy.…

kyro序列化踩坑记——提供方DTO新增字段,依赖方则报错

背景 A服务通过dubbo调用B服务&#xff0c;序列化方式选择的是kryo&#xff0c;A服务和B服务同时依赖C工程的一个DTO。 C工程的DTO新增了一个字段&#xff0c;deploy了&#xff0c;B服务引了最新的依赖。但是A服务并没有。 此字段&#xff0c;A服务并使用不上&#xff0c;也不…