I ended up not using this yet, but it returns a dictionary collection of all controls contained in a page, for example, and their current value. This includes textboxes, dropdowns, radios, and checkboxes.
I usually credit the original source for functions like these, but I lost where the recursive sub came from
' **************************************************************************
' purpose: function to call the recursive sub and then return the dictionary containing the results
Public Shared Function get_all_controls(ByVal container As Control) As Hashtable
htControls.Clear()
Dim strTemp As String = container.ID & " " & container.ClientID
strTemp = strTemp + container.UniqueID + " " + container.Page.Title
Diagnostics.Debug.Print(strTemp)
get_all_controls_recursive(container)
Return htControls
End Function
' **************************************************************************
' recursive sub to list all controls in a container
Public Shared Sub get_all_controls_recursive(ByVal container As Control)
Dim strTemp As String
Dim bFound As Boolean = False
For Each ctl As Control In container.Controls
bFound = False
strTemp = ctl.ID
If (Not bFound) Then
Dim txt As TextBox = TryCast(ctl, TextBox)
If (Not IsNothing(txt)) Then
htControls.Add(txt.ID, txt.Text)
bFound = True
End If
End If
If (Not bFound) Then
Dim ddl As DropDownList = TryCast(ctl, DropDownList)
If (Not IsNothing(ddl)) Then
htControls.Add(ddl.ID, ddl.Text)
bFound = True
End If
End If
If (Not bFound) Then
Dim chk As CheckBox = TryCast(ctl, CheckBox)
If (Not IsNothing(chk)) Then
htControls.Add(chk.ID, chk.Checked.ToString())
bFound = True
End If
End If
If (Not bFound) Then
Dim rdio As RadioButton = TryCast(ctl, RadioButton)
If (Not IsNothing(rdio)) Then
htControls.Add(rdio.ID, rdio.Checked.ToString())
bFound = True
End If
End If
If (ctl.Controls.Count > 0) Then get_all_controls_recursive(ctl)
Next
End Sub