Web頁面上的控件

Web頁面,即:.aspx文件
頁面的根目錄下,分爲了5部分
  [0]-{System.Web.UI.LiteralControl}
  [1]-{System.Web.UI.HtmlControls.HtmlHead}
  [2]-{System.Web.UI.LiteralControl}
  [3]-{System.Web.UI.HtmlControls.HtmlForm}
  [4]-{System.Web.UI.LiteralControl}html

內容依次爲:
[0]-{System.Web.UI.LiteralControl}
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" >this

[1]-{System.Web.UI.HtmlControls.HtmlHead}
  <head>
    ......
  </head>spa

[2]-{System.Web.UI.LiteralControl}
  <body>code

[3]-{System.Web.UI.HtmlControls.HtmlForm}
  <form>
    ......
  </form>orm

[4]-{System.Web.UI.LiteralControl}
  </body>
  </html>


xml

因此,在遍歷全部頁面上的控件的時候,就在this.Controls[3]中找.htm

 

問題:遍歷Web頁面上全部的TextBox,並所有設置爲1111

blog

    protected void btn_Click(object sender, EventArgs e)
    {
       
        foreach ( System.Web.UI.Control contrl in this.Controls[3].Controls)
        {
            if (contrl is System.Web.UI.WebControls.TextBox)
            {
                System.Web.UI.WebControls.TextBox txt = (System.Web.UI.WebControls.TextBox)contrl;
                txt.Text = "l";
            }
        }
    }

那麼遍歷WinForm中的控件呢?it

  private void button1_Click(object sender, EventArgs e)
        {
            foreach ( System.Windows.Forms.Control control in this.Controls)
            {
                if (control is System.Windows.Forms.TextBox)
                {
                    System.Windows.Forms.TextBox txt = (System.Windows.Forms.TextBox)control;
                    txt.Text = "bbbb";
                }
            }
        }
相關文章
相關標籤/搜索