Private Sub SomeCallingFunction
Dim ht As New Hashtable
RecurseControls(Me.Controls, ht)
End Sub
Private Function RecurseControls(ByVal controls As ControlCollection, ByRef htResults As Hashtable) As Hashtable
Dim i As Integer = 0
For Each ctrl As Control In controls
'do something with control
i = i + 1
If TypeOf ctrl Is TextBox Then
Dim txtBox As TextBox = ctrl
htResults.Add(txtBox.ID.ToString, txtBox.Text)
ElseIf TypeOf ctrl Is RadioButton Then
Dim rButton As RadioButton = ctrl
If rButton.Checked = True Then
htResults.Add(rButton.ID.ToString, rButton.Attributes("Value").ToString)
End If
End If
'recurse
If ctrl.HasControls() Then
RecurseControls(ctrl.Controls, htResults)
End If
Next
htResults.Add("Count", i)
RecurseControls = htResults
End Function
|