zoukankan      html  css  js  c++  java
  • 遍历页面上的所有控件

           /// <summary>
            /// 采用递归的方法来遍历页面控件
            /// </summary>
            /// <param name="parent"></param>
            protected void ErgodicChildrenControls(Control parent)
            {
               
                foreach (Control c in parent.Controls)
                {

                    //此处写有关控件的代码,例如    

                  //if (c is HtmlInputButton)
                   // {

                   //    HtmlInputButton btn = (HtmlInputButton)c;

                   //   if (c.id =="save")

                  // {
                  //      c.Visble=true;

                  //     }
                   // }


                     if (c.Controls.Count > 0)       // 判断该控件是否有下属控件。
                    {
                        ErgodicChildrenControls(c);    //递归,访问该控件的下属控件集。
                    }
                }
            }

     注意:该方法只能遍历服务器(即 runat=server)控件

    调用的方法:

    protected void Page_Load(object sender, EventArgs e)
       {  

                  ErgodicChildrenControls(this);
       }

  • 相关阅读:
    奥巴马邻居卖房的启示,彻底改变你的思维!
    CentOS7.0安装Nginx 1.7.4
    CentOS 7 下安装 Nginx
    C# 关于线程锁lock的使用方法
    内存屏障、编译屏障:
    linux环境下安装nginx步骤
    一、为什么要学习Java虚拟机?
    Linux CentOS系统上安装Eclipse
    poj 3311 Hie with the Pie (TSP问题)
    怎样初始化一个指针数组
  • 原文地址:https://www.cnblogs.com/xjb/p/965192.html
Copyright © 2011-2022 走看看