You can loop through the controls collection.
However it gets complicated if you have controls nested within other
container controls.
Here's some code Kevin Spencer posted a while back that provides a good
demonstration using recursion.
Private Function FindChildControl(ByVal objSearchControl As
System.Web.UI.Control, _
ByVal strControlID As String) As Object
Dim objChildControl As System.Web.UI.Control
Dim objControl As System.Web.UI.Control
If objSearchControl.Controls.Count = 0 Return Nothing
For Each objChildControl in objSearchControl.Controls
objControl = FindChildControl(objChildControl, strControlID)
If Not IsNothing(objControl) Return objControl
Next
Thanks. This code searches for a given control name in a control that itself
has controls. I have not been sucessful yet in adapting it to loop through
the Page.Controls object for my "Form1" to get all the controls.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.