Here's a little code snippet that will search a collection of Controls for the first control of a specified type.
private object FindControlByType( Control root, Type t ){ if ( root != null && root.GetType().Equals( t ) ) return root; foreach( Control c in root.Controls ) { object node = FindControlByType( c, t ); if ( node != null && node.GetType().Equals( t ) ) return node; } return null;}
Example: the following example returns the first instance of an HtmlForm in a Page's Control collection:
HtmlForm form = (HtmlForm) FindControlByType( Page, typeof( HtmlForm ) );
Remember Me
a@href@title, i, strike, u
Copyright © 2003-2008 Falafel Software Inc.
Subscribe to Falafel Blogs
The opinions expressed herein are Falafel's employees own personal opinions and do not represent Falafel Software's view in any way in case they go bananas!