Recursive Find Control in VB.NET

Recursive FindControl

Reference:

Public Shadows Function FindControl(ByVal id As String) As Control

Return FindControl(Of Control)(Page, id)

End Function

Public Shared Shadows Function FindControl(Of T As Control)(ByVal startingControl As Control, ByVal id As String) As T

Dim found As Control = startingControl

If (String.IsNullOrEmpty(id) OrElse (found Is Nothing)) Then Return CType(Nothing, T)

If String.Compare(id, found.ID) = 0 Then Return found

For Each ctl As Control In startingControl.Controls

found = FindControl(Of Control)(ctl, id)

If (found IsNot Nothing) Then Return found

Next

Return CType(Nothing, T)

End Function


 
 
Maint