Hi Matt,
Or, even easier...
C#:
foreach (UserControl uc in this.Page.Controls)
{
// do something
}
Did you try this out? It won't work. Why? Because the User Controls are in
the WebForm, which is in the Page. You have to loop through the Form's
Controls Collection, not the Page's.
And what if the Control is nested inside another Control? The Controls
Collection of a Control doesn't contain the nested Controls. They are in the
Controls Collections of the Controls they immediately reside in.
The only way to truly find a Control whose location is not exactly known is
to use a recursive function that checks all Controls inside a given
Control's Controls Collection, and then calls itself for each Control in
that Collection. And start from the Form, not the Page, unless you expect a
given Control to be outside the form.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living