Better way to do Parent.Parent.Parent.Parent....

I want to find a tabstrip on the page, then hide a couple of them.  Seems like it takes 5 or 6 .Parents to get to the node with the control before I can do a FindControl

 Is there a better way to do this?

3/29/2009 11:51:12 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 25
Get it on Google Play
Get it on Apple App Store


You can try implementing a Recursive FindControl method that will drills into child controls in  Page.



"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
3/30/2009 4:48:33 AM

 You could do something a bit more elegant using an extension method like this:


public static class ControlExtensions

    /// <summary>
    /// Find a parent control by type.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ctrl"></param>
    /// <returns></returns>
    public static T FindParent(this Control ctrl) where T : Control
        T found = null;
        Control current = ctrl;

        while (current != null)
            if (current is T)
                found = (T)current;

            current = current.Parent;
        return found;

Which you would call like this:
public class MyControl : System.Web.UI.UserControl
    public void Page_Load(object sender, EventArgs e)
        //find a parent gridview
        GridView gv = this.FindParent<GridView>();

        if (gv != null)
            //do something with gridview
My Blog
3/30/2009 2:12:41 PM

 Thanks guys!

3/30/2009 2:19:37 PM

Similar Artilces:

Parent of the parent
Hey guys, How can I trigger events on the parentwindow of the parentwindow ... ? I know that it has to do something with : lw_parent = n_pass_data.of_get_parent_sheet() And then lw_parent.of_get_parent_sheet() Or something like that ... I hope someone can help me ... Thnx in advance, Greetz Bart ! First step is to get the window you are on. If you've got PFC, or can install it with the custom installation, look at of_GetParent() on most (all?) visual user objects in the PFC layer, like pfc_u_dw. It basically does GetParent() in a loop until it finds one of t...

I've got a DataSet with four DataTable's in it. Each table is a parent to another table, each having a DataRelation joining them. I need to do a Compute on the bottom most child table, and in my filter expression I want to only compute records whose parent's parent has a certain column value. The problem is that the expression parameter doesn't allow cascading upwards for parent rows. "Parent.Column" works just fine, but "Parent.Parent.Column" doesn't. I really didn't expect it to, but I was giving ADO the benefit of the doubt. Is there any clean way around this? Since the DataTable object i...

using parent.parent
I have two user objects, a tab control u_cst_control and a tabpage u_cst_page. They happen to be inherited from PFC objects, but I don't think that's relevant. If I can put this script in an event on u_cst_tabpage, and it works fine... parent.dynamic of_Test() Why can't I put this script in an event on a dw on u_cst_tabpage? parent.parent.dynamic of_Test() The syntax seems OK, since the error I get is "parent is not an attribute of u_cst_tabpage" In other words, it found the first level parent OK - got its name right anyway. What approach shoul...

pb803(9704) my script: open(wr_test,w_parent) Question: which message does powerbuilder kept w_parent in. I checked message.PowerObjectParm, but it is null in the open event of wr_test. In wr_test, I need to know the parent window, so I can fire an event from the parent. Please show me the function to get the parent in wr_test. Thanks. Julie; If PowerObjectParm is NULL, then when you pass w_parent, it must be null as well (NO reference) Where is this script located? HTH, Austin <Julie> wrote in message > pb803(9704) ...

popup window to parent and parent to popup
HI I have parent window when i click the link in the parent window it will give me popup window and there some other links(code is below) in popup window. when i click them it has to go to parent window where should i write the code and what should i write <asp:DataList ID="dlTopTenResults" runat="server" Width="100%"> <ItemTemplate> <table > <tr> <div style ="border-bottom: 1px solid #E7E2B8; height:1px;"> <td width="7%" valign="middle"><span class="story_in_page_title"...

Parent..Child Getting the Child to talk with the Parent..
If i launch a child window or popup from the parent (web forms).. can the child read from a datagrid that lives on the parent?  if so.. how??  what about usiong a session.. something like this./ ChildDS = (System.Data.DataSet) Session["ChildDS"]; how long does this last?? is this a good way of doing it?? That would work and the default timeout is 20 minutes or as long as the Session is active. Is this a good way depends more on your circumstances. Do you need the entire Grid? Then yes. If not, think of a new way, such as passing only what's needed. NC...   ...

Replicating a parent table that is not the main (parent) table in a publication...
We have 5 tables in the following format: 1) SubscriptionBaseTable UserIdColumn <pk> ParentTableSubscribeColumn <pk> UserIdSubscribeColumn 2) ParentTable PrimaryKeyColumn <pk> ParentTableSubscribeColumn (data columns...) 3) ChildA_OfParentTable 4) ChildB_OfParentTable 5) ChildC_OfParentTable We want to use table 1 (SubscriptionBaseTable) to allow for our remote users to subscribe to the other 4 tables dynamically. This is because there can a lot of replication (with large amts of data) going on for these 4 tables and rather than have them having to ...

Override table css from parent css and parent class
Hi,    We have created several css files, where table class (css) exists with border style defined with border 1px black solid, not I override this table class inside a grid setting border to 1px white solid, now I want to override this table class for pagerstyle css class setting border to 0 or none...How can I achieve this???   I have somewhat resolve this problem after scratching head and other things...This happens when learning something you have not mastered yet ...

Passing Value from the Child Window to the Parent (And do a Parent Refresh)
Okay here is the code to open a new window (Child window). In the child window we have a gridview with checkboxes. You select certain items from the gridview. And press the button control and those items that are selected are displayed on the Parent page (Parent page automatically refresh) using the child page. Parent Page Code: using System; using System.Data; using System.Configuration; /*  * Mohammad Azam  *  *  * MCP  *  *  * */ using System.Web; using System.Web.Security; using Syste...

Promote Child Portal to Parent and Parent Portal to Child
Here is my situation. When I created our website at work, we were in charge of a Division of the company in a Directorate, Division, Branch style setup. So I developed the site with the Division as the parent. Now we have been requested to re-do and start maintaining the Directorate level website and all childs. So how do I promote a Child Portal (Directorate) to the Parent Portal and my current Parent Portal (Branch) to a child? I tried changing the portal aliases to no avail. Any other suggestions?Jeremy...

how to get reference to parent page and/or parent user control
I have a server control that needs to access either the immediate user control that contains it, if the control is directly contained in a usercontrol, or get the parent page. The reason it needs to do so is to determine whether these implement a particular Interface that exposes certain methods that determine the server control behaviour. By using "this.Page" it is easy to gain access ot the page, but I am not sure how one goes about getting the parent usercontrol. Is looping up the parent control hierarchy the only option? Thanks, Olja olja:Is looping up the parent control hierarchy t...
Name: Speerrylayelo Email: styclesepataoldotcodotuk Product: eBay Companion Summary: - single parent dating online Comments: <B></B> As a single mom or dad, you know how tough it can be to be a single parent. By the time you have the kids dropped off for school, you still have to go to work, cook, clean, do laundry and many other activities that take up every second of the day. Its not easy being a single parent and it certainly can be lonely. When you do try to date, you can discover that many men and women do not want to ...

Refresh Web form (parent) when submiting Web User Control
I got one Web form that contains one Web user control. The web form is displaying some data that is stored in database and Web User Control to edit this data and save the changes to database. When I press submit button in user control the data is getting stored in db, but Web form is not updated with this new changes ( i think this is because of the callback ). If I refresh the page then i see the changes. How can I make user control fire the refresh event in web form? If you have a answer pls give me a example or point to one tutorial, its much easier to understand! Thanks for your time!...

Selecting Parent's Parent (Grandparent?) of found childNode
Hi all, I have an XML document that looks a litle like this: <portfolio> <main name="Commercial"> <category name="Wedding"> <image isFeatured="yes" src="blah.jpg" thumb_src="blah.jpg" title="image 1" active="yes" UID="1" /> <image isFeatured="no" src="blah2.jpg" thumb_src="blah2.jpg" title="image 2" active="yes" UID="2" /> </category> <category name="Events&...

Web resources about - Better way to do Parent.Parent.Parent.Parent.... -

Martin Luther King Jr. Day Celebrations
Roanoke Times Martin Luther King Jr. Day Celebrations Roanoke Times The activities in the Roanoke Valley celebrating Martin Luther King, Jr. ...

Academy president 'heartbroken' over #OscarsSoWhite, vows more action
LOS ANGELES — Cheryl Boone Isaacs, speaking on behalf of the Academy of Motion Picture Arts and Sciences of which she is president, issued a ...

R.I.P, Glenn Frey
In honor of Glenn Frey, classic rock radio stations will be playing The Eagles all day for the past 25 years. — ⚡David Angelo⚡ (@MrDavidAngelo) ...

Family members and congressmen reunited with freed Americans
NDTV Family members and congressmen reunited with freed Americans Sacramento Bee Jason Rezaian, the Washington Post reporter who was freed ...

China's growth hits quarter-century low, raising hopes of more stimulus
By Pete Sweeney and Samuel Shen SHANGHAI (Reuters) - China's economy grew at its weakest pace in a quarter of a century last year, raising hopes ...

US Court Bans Older Samsung Devices From Being Sold
The patent war between Apple and Samsung is still going on. Maybe it isn’t as fierce as it once was, and from what we have heard, both companies ...

WhatsApp Does Away With $0.99 Per Year Fee, Is Now Free to Use
That nominal $0.99 per year fee for WhatsApp is coming to an end, with a blog post from WhatsApp today announcing that over the next month, they ...

9-year-old actor Jacob Tremblay had the cutest awards ceremony in history
9-year-old Jacob Tremblay took home the Critics' Choice Award for Best Young Performer for his work in Room on Sunday Night, and more importantly, ...

Netflix renews 'Jessica Jones,' reveals premiere dates
WGNO Netflix renews 'Jessica Jones,' reveals premiere dates WGNO Netflix also announced premiere dates Sunday for these new and returning ...

China Box Office: ‘Star Wars’ Wins Week, Edged Out in Second Weekend
“The Force Awakens” topped the Chinese box office in its first full week. But in its second weekend it was beaten by “Boonie Bears III.

Resources last updated: 1/19/2016 10:58:26 AM