簡體   English   中英

頁面上的ASP.net額外控件

[英]ASP.net extra controls on page

我必須在頁面上列出所有控件。 我這樣做

protected void listControls(Control c)
{
    if (c.HasControls())
    {
        tb_message.Text += String.Format("{0}{1}", c.ID, System.Environment.NewLine);
        foreach (Control control in c.Controls)
        {
            tb_message.Text += String.Format("{0}{1}", control.ID, System.Environment.NewLine);
            listControls(control);
        }
    }
}

為什么這樣的輸出(在開頭加上兩個額外的空行)

    form1

    tb_life_cycle

    tb_message

    btn_button

如果我只有以下控件:tb_life_cycle,tb_message,btn_button +表單form1? 謝謝

ASP.NET Web窗體向Control集合中添加了多個控件,以便它可以呈現諸如純文本(定義為ASPX設計器的一部分)之類的東西。您可能會發現,輸出中並沒有期望的多余控件是ASP.NET生成的LiteralControl

還嘗試在輸出中包括每個控件的Type

protected void listControls(Control c) {
    if (c.HasControls()) {
        litText.Text += String.Format("{0}{1}{2}", c.GetType(), c.ID, System.Environment.NewLine);
        foreach (Control control in c.Controls) {
            litText.Text += String.Format("{0}{1}{2}", control.GetType(), control.ID, System.Environment.NewLine);
            listControls(control);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM