ExtensionMethod.NET Home of 818 C#, Visual Basic, F# and Javascript extension methods

FindControlByType

Used in conjunction with GetChildren(), it will return a T from a list of children of a control. If you are looking to return a list of T, use FindControlsByType() at http://www.extensionmethod.net/Details.aspx?ID=310 Get Children is located at: http://www.extensionmethod.net/Details.aspx?ID=309

Source

public static T FindControlByType<T>(this Control ctrl)
{
  return ctrl.GetChildren().OfType<T>().SingleOrDefault();
}

Example

DistinctType dt= Control.FindControlByType<DistinctType>();

Author: Ryan Helms

Submitted on: 18 jul 2010

Language: C#

Type: System.Control

Views: 2918