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);
       }

  • 相关阅读:
    关于c:fakepath的解决办法
    golang channel 源码剖析
    深入虚拟内存(Virtual Memory,VM)
    浅析 golang module
    浅析 golang interface 实现原理
    Golang channel实现
    LCS(最长公共字序列)实现
    Golang令牌桶-频率限制
    OpenGL(3)-三角形
    OpenGL(2)-窗口
  • 原文地址:https://www.cnblogs.com/xjb/p/965192.html
Copyright © 2011-2022 走看看