Hi,
Remember, some of those controls contain controls themselves. Your code
sample doesn't recurse the control tree, it just iterates the top level
parent controls. You must write a recursive function similar to the
following (c#):
private void RecurseControls(ControlCollection controls)
{
foreach(Control c in controls)
{
//do something with control...
//recurse
if(c.HasControls())
RecurseControls(c.Controls);
}
}
Or in VB.NET:
Private Sub RecurseControls(ByVal controls As ControlCollection)
For Each control As Control In controls
'do something with control
'recurse
If control.HasControls() Then
RecurseControls(control.Controls)
End If
Next
End Sub
--
Ben
http://bitarray.co.uk/ben
"Shawn" <Sh***@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com...
Hi. I'm trying to loop through all webcontrols in my
System.Web.UI.HtmlControls.HtmlForm.
This is my code:
Dim form As HtmlForm
Dim control As Control
form = Me.FindControl("completion")
For Each control In form.Controls
...
Next
Looking at the form.Controls.Count property it says that there are 109
controls on my page, but the For Each statement only does one loop where
it
returns a LiteralControl. Am I missing something here? Shouldn't the loop
execute 108 times??
Thanks,
Shawn