Nested MasterPage FindControl

Posted on 2007-08-08
Last Modified: 2008-01-09
I have a nested masterpage setup and I am having trouble finding a panel control I need access to.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="HTG.master.cs" Inherits="MasterPage" %>
<html xmlns="">
<title> </title>

<form id="form1" runat="server">          
<asp:contentplaceholder id="ContentPlaceHolderMain" runat="server"></asp:contentplaceholder>

MasterPage 2:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="APP.master.cs" Inherits="PBE.MasterPage" MasterPageFile="~/HTG.master" %>

<asp:Content ID="ContentMain" ContentPlaceHolderID="ContentPlaceHolderMain" runat="Server">

<asp:Panel ID="PanelINeedAccessTo" runat="server">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

I need to be able to access PanelINeedAccessTo from any page loading into ContentPlaceHolder1&

I have tried doing a find control on the ContentMain ContentPlaceHolder:
            ContentPlaceHolder myContentPlaceHolder = new ContentPlaceHolder();
            myContentPlaceHolder = (ContentPlaceHolder)(Master.FindControl("ContentMain"));
Returns null&

Please help!

Question by:Nugs
    LVL 8

    Expert Comment

    try like this

    myMasterPage myMaster = (myMasterPage)this.Master;
    ContentPlaceHolder myContentPlaceHolder = myMaster.FindControl("myContentPlaceHolder ") as ContentPlaceHolder ;
    myContentPlaceHolder = (ContentPlaceHolder)(Master.FindControl("ContentMain"));
    LVL 8

    Accepted Solution

    LVL 2

    Author Comment


                ContentPlaceHolder myContent = new ContentPlaceHolder();
                myContent = (ContentPlaceHolder)(Page.Master.Master.FindControl("ContentPlaceHolderMain"));

                Panel myPanel = new Panel();
                myPanel = (Panel)(myContent.FindControl("PanelINeedAccessTo"));

    Thanks for the input...

    Much Appreciated


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now