I have to list all controls on a page. I do it like so
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);
}
}
}
Why is the output like this (+ an extra two empty lines at the beginning)
form1
tb_life_cycle
tb_message
btn_button
If I only have the following controls: tb_life_cycle, tb_message, btn_button + the form form1? Thank you