Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FindControl - In "Parent" page

Posted on 2008-06-19
4
Medium Priority
?
2,456 Views
Last Modified: 2008-07-12
I have a usercontrol being bound to a placeholder - there is a button within the usercontrol that, when clicked, would like to find a control (a placeholder) and load/bind another usercontrol - so need to know how to find a control, on the parent, from within the child usercontrol...
0
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 21827804
You can use:
      PlaceHolder ph =     (PlaceHolder)  Page.FindControl("PlaceHolderID");
0
 

Author Comment

by:tbaseflug
ID: 21845868
Actually, this is more of what I am looking for - which works, but looks pretty ugly

 Parent.Parent.Parent.Parent.Parent.FindControl("UpdatePanel2") as UpdatePanel;

Open in new window

0
 
LVL 16

Accepted Solution

by:
ororiole earned 2000 total points
ID: 21849283
Well you didnt mention several Parent.Parent.Parent levels. Why would you want to do that, when you can start at Page and recurse thru the control collections? Plus you are hard coded, so if you add or remove Parents, you have to change your code. This way you can start at Page (or lower if you wish) and it will find the control no matter what the level.
       private Control SearchControl(Control container, string id)
        {
            Control control = container.FindControl(id);
            if (control == null)
            {
                foreach (Control c in container.Controls)
                {
                    if (c.HasControls())
                    {
                        control = SearchControl(c, id);
                        if (control != null) break;
                    }
                }
            }
            return control;
        }

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question