FInd Control by ID ?

Jarod

Regular
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 ? (can't 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,
 
You'd have to loop through checking their .Name property I suppose. Controls don't really have names as such, so if you're creating them at runtime it's 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