asp.net中遍曆套用主版頁面的頁面的控制項

來源:互聯網
上載者:User

標籤:for   sp   on   html   bs   as   htm   .net   tt   

應該搞清楚控制項在第幾層

我們所要找的控制項一般在第四層site1_master---ContentPlaceHolder---HtmlForm---CheckBox

第一層是site1_master,母片

第二層是ContentPlaceHolder,是母片的’坑‘,

第三層是HtmlForm,就是HTML表單,

第四層就是子控制項了

所以要多層遍曆

下面例子是用多層遍曆找頁面中的CheckBox,並列出各層名稱

string  s="";

for (int i = 0; i < Page.Controls.Count; i++)  //site1_master中所有控制項
{
  foreach (Control conn in Page.Controls[i].Controls)//在site1_master中中遍曆,尋找ContentPlaceHolder
  {
      foreach (Control con in conn.Controls)//在ContentPlaceHolder中遍曆,尋找HtmlForm
      {
           foreach (Control c in con.Controls)//在HtmlForm中遍曆,尋找CheckBox
          {
             if (c.GetType().Name.Equals("CheckBox"))
               {
                  s=conn.GetType().Name + "---" + con.GetType().Name + "---" + c.GetType().Name ;
              }

          }               
       }

   }
}

 

新手,有錯誤請及時指正,謝謝了!

asp.net中遍曆套用主版頁面的頁面的控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.