Access Visibily Master Page from a child page

Hello,

I have a master page Site.Master with a button inside. In my child page, his master page is Test.Master. Test.Master is a Nested Master Page from Site.Master.
From my child page, i want access this button with my code below :
Button mybutton = (Button)this.Page.Master.FindControl("LoginButton");
            mybutton.Visible = false;

Open in new window


But the mybutton can't access and return me null. So i have an error and can't change the visibily.

Thanks.
bruno_boccaraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

try this code

MainContent is the ID of the ContentPlaceHolder of top most master page.

           ContentPlaceHolder cp = this.Master.Master.FindControl("MainContent") as ContentPlaceHolder;
            if (cp != null)
            {
                Button mybutton = cp.FindControl("LoginButton") as Button;
                mybutton.Visible = false;
            }

Open in new window

0
bruno_boccaraAuthor Commented:
The object reference is not define like object instance. It's the same error.

System.NullReferenceException

Ligne 30 :         protected void Page_Load(object sender, EventArgs e)
Ligne 31 :         {
Ligne 32 :             ContentPlaceHolder cp = this.Master.Master.FindControl("MainContent") as ContentPlaceHolder;
Ligne 33 :             if (cp != null)
Ligne 34 :             {

Open in new window

0
Lokesh B RDeveloperCommented:
Hi,

Did you change the content place holder ID?

Can you post the mark up for site master?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

bruno_boccaraAuthor Commented:
Hi, this is the code for site master.

<body>
    <header>
        <div id="logo"></div>
        <asp:Panel ID="Panel1" runat="server">
          <div id="connexion_module">
            <form id="FormLogin" runat="server">
                <asp:Login ID="Login1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#333333" CreateUserText="Sign In" CreateUserUrl="~/Registers/Register.aspx" CssClass="active" Height="100px" LoginButtonText="Log In" PasswordLabelText="Password&nbsp;:" PasswordRecoveryText="Forget Password" PasswordRecoveryUrl="~/Registers/ForgetPassword.aspx" RememberMeText="Remember Me " TitleText="Log" UserNameLabelText="Mail : " VisibleWhenLoggedIn="False" Width="458px" OnAuthenticate="Login1_Authenticate">
                 <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
                 <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="2px" Font-Names="Verdana" Font-Size="Smaller" ForeColor="#284775" Font-Overline="False" Width="100px" />
                 <TextBoxStyle Font-Size="0.8em" />
                 <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
            </asp:Login>
            </form>
        </div>       
        </asp:Panel>

    </header>
     <div id="menu2">
         <asp:ContentPlaceHolder runat="server" ID="MenuContent" />
     </div>
    <div id="body">
    <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />
      <section class="content-wrapper main-content clear-fix">
            <asp:ContentPlaceHolder runat="server" ID="MainContent" />
            
        </section>  
     </div>

Open in new window


this the code for test master :

<asp:Content ID="ContentID1" ContentPlaceHolderID="MainContent" runat="server">
 <div id="sse2">
        <div id="sses2">
        <ul>
            <li>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default.aspx">Accueil</asp:HyperLink>
            </li>
            <li>
                <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/MainPage/Support.aspx">Support</asp:HyperLink>
            </li>
            <li>
                <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/MainPage/About.aspx">About</asp:HyperLink>
            </li>
        </ul>
        </div>
        </div>
    <asp:ContentPlaceHolder runat="server" ID="FeaturedContent" />     
    <asp:ContentPlaceHolder runat="server" ID="Content2" />
</asp:Content>

Open in new window


this is the header of my child page :

<%@ Page Title="" Language="C#" MasterPageFile="~/Test.master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Berechit.Registers.Register" %>

Open in new window


I do all this because i want two form runat server to one page... Maybe there is another way ?
0
Lokesh B RDeveloperCommented:
Hi,

try the following.

Button mybutton = this.Master.Master.FindControl("LoginButton") as Button;
mybutton.Visible = false;

Open in new window

0
bruno_boccaraAuthor Commented:
Hi,
Same Error.

But like i say to you.  I do all this because i want two form runat server to one page... Maybe there is another way ?.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bruno_boccaraAuthor Commented:
Anyone answer it correctly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.