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

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-12-08
  • 2021-12-08
  • 2021-09-02
  • 2022-12-23
  • 2022-01-31
猜你喜欢
  • 2021-11-21
  • 2021-12-02
  • 2021-07-03
  • 2021-12-01
  • 2021-10-19
  • 2022-01-09
相关资源
相似解决方案