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 (ControlCollect ion controls)
{
foreach(Control c in controls)
{
//do something with control...
//recurse
if(c.HasControl s())
RecurseControls (c.Controls);
}
}
Or in VB.NET:
Private Sub RecurseControls (ByVal controls As ControlCollecti on)
For Each control As Control In controls
'do something with control
'recurse
If control.HasCont rols() Then
RecurseControls (control.Contro ls)
End If
Next
End Sub
--
Ben
http://bitarray.co.uk/ben
"Shawn" <Sh***@discussi ons.microsoft.c om> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
Hi. I'm trying to loop through all webcontrols in my
System.Web.UI.H tmlControls.Htm lForm.
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.C ount 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