First, the Page does not contain very many Control in its Controls
Collection. Usually it contains a few Literal Controls and a WebForm
Control. The WebForm Control contains most of the Controls in the Page.
However, some of the Control are probably nested as well. For example, if
you use any UserControls, they almost always contain other Controls.
Now, the Controls Collection of any Control is limited to the Controls that
are immediately under that Control, not those that are nested inside them.
So, you would need to use Recursion to see all of the Controls in the Page.
This is generally done via a recursive function (a function that calls
itself) which takes a Control as a parameter, loops through the Controls in
the Control's Controls Collection, calling itself for each Control.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.
"Rodusa" <rc**********@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I am trying to loop all controls in a form with no success. For
example, Let's say we place three TextBoxes in the form and we use the
code below:
foreach (Control c in Page.Controls)
{
Response.Write(c.ID);
}
It is returning nothing. I check the <form runat="server"> and it is in
there.
What is wrong?
Rod