C#: Get Parent Control with Generics

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

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

<br />
private Control GetParentControl<T1>(Control control)<br />
{<br />
if (control.Parent.GetType() == typeof(T1))<br />
{<br />
return control.Parent;<br />
}<br />
else<br />
{<br />
return GetParentControl<T1>(control.Parent);<br />
}<br />
}</p>
<p>
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
C#: Get Parent Control with Generics Pieter Brinkman avatarAuthor: Pieter Brinkman ()

Pieter is Technical Marketing Manager for Sitecore Netherlands and owner of Gaatverweg.nl. He has more than ten years experience with software developing in multiple programming languages and with different Content Management Systems. Before joining Sitecore Pieter was a lead developer for multiple Sitecore and .Net projects, he joined Sitecore in 2011 as an Solution Architect in The Netherlands, after two years as an Solution Architect he joined the Technical Marketing department. In the role as Techinical Marketing Manager he is responsible for the Global MVP program and the Sitecore technical branding strategy. You can follow Pieter on twitter: @pieterbrink123 or Google+

C#: Get Parent Control with Generics WebsiteC#: Get Parent Control with Generics TwitterC#: Get Parent Control with Generics Google PlusC#: Get Parent Control with Generics Linkedin

Related posts

Design Patterns(C#): Basic example Strategy pattern
Asp.Net: invoke WCF method with WCF Test Client
LINQ: Creating a if statement in Linq query
WCF webservice error with DBML objects

0 Responses to C#: Get Parent Control with Generics

Comments
Tweets
Pingbacks
  • Click on a tab to select how you'd like to leave your comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>