C#: Get Parent Control with Generics

by Pieter Brinkman 27. April 2010 04:43

I use the following method to return a parent control of a specific type. This method is recursive and uses generics.

[code:c#]

private Control GetParentControl<T1>(Control control)
{
    if (control.Parent.GetType() == typeof(T1))
    {
        return control.Parent;
    }
    else
    {
        return GetParentControl<T1>(control.Parent);
    }
}

[/code]

Tags: , , , ,

ASP.Net | C# | Controls

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am Solution Architect for Sitecore in The Netherlands. My interests are mainly ASP.NET, MSSQL and Content Management Systems.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

RecentComments

Comment RSS

Most comments