Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:18:01+00:00 2026-06-01T19:18:01+00:00

In jQuery there is a cool function called .parents(‘xx’) that enables me to start

  • 0

In jQuery there is a cool function called .parents(‘xx’) that enables me to start with an object somewhere in the DOM tree and the search upwards in the DOM to find a parent object of a specific type.

Now i’m looking for the same thing within C# code. I have an asp.net panel which sometimes sits in another parent panel, or sometimes even 2 or 3 parent panels and i need to travel upwards through these parents to finally find the UserControl that i’m looking for.

Is there an easy way to do this in C# / asp.net?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:18:03+00:00Added an answer on June 1, 2026 at 7:18 pm

    Edit: after rereading your question, I had a stab at it based on the second link in my post:

    public static T FindControl<T>(System.Web.UI.Control Control) where T : class
    {
         T found = default(T);
    
         if (Control != null && Control.Parent != null)
         {
            if(Control.Parent is T)
                found = Control.Parent;
            else
                found = FindControl<T>(Control.Parent);
         }
    
         return found;
    }
    

    Please note, untested, just made this up now.

    Below for reference.

    There’s a common function called FindControlRecursive where you can walk the control tree from the page down to find a control with a specific ID.

    Here’s an implementation from http://dotnetslackers.com/Community/forums/find-control-recursive/p/2708/29464.aspx

    private Control FindControlRecursive(Control root, string id) 
    { 
        if (root.ID == id)
        { 
            return root; 
        } 
    
        foreach (Control c in root.Controls) 
        { 
            Control t = FindControlRecursive(c, id); 
            if (t != null) 
            { 
                return t; 
            } 
        } 
    
        return null; 
    }
    

    You could use this like:

    var control = FindControlRecursive(MyPanel.Page,"controlId");
    

    You could also combine it with this: http://weblogs.asp.net/eporter/archive/2007/02/24/asp-net-findcontrol-recursive-with-generics.aspx to create a nicer version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In jQuery there is $.extend() function. That basically works like matching default settings with
Is there any JQuery method/implementation that equivalent to YUI.getElementsBy? YUI.getElementsBy ( method , tag
Is there a jQuery way to perform iteration over an object's members, such as
Is there a jQuery project out there, that create on of these Password-strength-meters right
Is there a jquery plugin that when you hover over an icon etc. it
Is there a jQuery plugin or javascript library that supports a genie animation effect
jQuery has the very cool feature/method .data, I wonder if there is a way
Consider the following example: HTML: <div id=cool-div></div> JS/jQuery: var ComplexObject = function() { this.Append
I know there are some cool themes on the jQuery website, but I need
In jQuery, is there another way to write this? Version 1 $(#date_filter-enable).click(function() { $(#search_dates).removeClass(hidden);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.