Olaf said:
Hi,
the controls-collection applies to all controls. That is, if you have i.e.
a panel, you can loop through all its contained controls using i.e.
for i as integer=0 to pnlYourPanel.controls.count-1
response.write pnlYourPanel.controls(i).id
next
(A for-each is possible as well.)
Cheers,
Olaf
Olaf,
Thanks, but I really didn't word the question quite correctly.
My user control contains about 45 ASP.Net controls such as labels,
buttons, and drop down lists. (This doesn't include the list items
within the DDLs which are also ASP.Net controls.)
In default.aspx, I want to find all the controls that have been loaded
into the placeholder. But for some reason, I can only list about
a third of them using the following code...
ctl_1 = Page.LoadControl("~/UserControls/MyControl.ascx");
plcHol1.Controls.Add (ctl_1);
// ...
foreach (Control ctl in ctl_1.Controls)
Response.Write(ctl_1.ID + "<br>");
Every control has an ID.
But I can still find a specific control which doesn't appear using
the above by using refraction. That is,
if (ctl_1.FindControl("lblSomeLabel") != null)
Write.Response ("lblSomeLabel exists.")
What I think is happening is that controls that are contained
in tables nested inside tables don't show in the Controls
collection, but can be "smoked" out using refraction.
Of course I don't want to resort to this, because it's
slow, and I have to run this process many times.
Any ideas? Or does anyone see something obvious that
I'm overlooking?