Find Controls Recursively
Category:
C#, VB.NET, ASP.NETType:
SnippetsDifficulty:
BeginningAuthor:
AnonymousVersion Compatibility: Visual Basic.NET
More information:
This code snippet was useful when I needed to access a control inside another control. This function finds the first control with the name you pass in for a page or control. If you give it 'Page' as the first argument, it will give you the first control used on the page. To find a control on a Page with ID="WantToFindThis", Dim ThisControl As Control = RecursiveFindControl(Page, "WantToFindThis"). And if you wanted to change the text of that control, ThisControl.Text = "Something new". Warning: This may not find the control you are after if you have several controls on the page with that name.
Instructions: Copy the declarations and code below and paste directly into your VB project.
Declarations: