FInd Control by ID ?

Jarod

Well-known member
Joined
Feb 5, 2003
Messages
82
Location
Bruxelles
In Web development wa can use a method called System.Web.UI.Control.FindControl(string) to get a control by its ID. So in a Page (inheriting from Control by default) we can easily get any control of that page.

Do I have missed the equivalent of that function for the System.Windows.Forms.Control ?
I know we have access to the ControlCollection of a form but if I have a textBox on my Form named "TextBox1", how can I get it ? (cant use me.TextBox1 if the control has been added dynamically)
No other solution to get an enumerator on the ControlCollection and test all control ????

Thanks,
 
Youd have to loop through checking their .Name property I suppose. Controls dont really have names as such, so if youre creating them at runtime its best to keep a reference to them around somewhere, either in a hashtable or you can just rely on the .Name property and loop through the Controls collection.
 
Back
Top