1

I have a master page with couple ContentPlaceHolder inside it and added some content page of this master page.

I would like to set Visible="False" on one asp:Content in some page but it's not working as I'm still able to view data of both asp:Content controls.

Why?

Master page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterBase.Master.cs" Inherits="MasterBase" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">          

        </head>        
        <body>
            <form id="form1" runat="server">
                <!-- HEADER -->
                <asp:ContentPlaceHolder ID="head" runat="server" />

                <!-- CONTENT -->
                <asp:ContentPlaceHolder ID="bodyContent" runat="server" />

                <!-- FOOTER -->
                ...
            </form>
        </body>
</html>

Content Page

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server" Visible="False">
      <!-- Some Data -->
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">
     <!-- Some Data -->  
</asp:Content>
Nope
  • 22,147
  • 7
  • 47
  • 72
Surya
  • 168
  • 4
  • 19
  • Does it work if you set Visible="False" in the Master page? Just as an experiment. – Licht Mar 28 '17 at 12:48
  • @Licht if I set Visible="False" in the Master page, then it will affect other content page where I would like to show it. Only in some specific page I want to set Visible="False". – Surya Mar 28 '17 at 12:52
  • 1
    The `visible` seems to be ignored on `asp:content`, you could wrap a `panel` around the required `content` and set the `visible` status there. That seems to be the general solution applied. – Nope Mar 28 '17 at 12:56
  • @Fran thank for improvise my question, if visible attribute is ignored on asp:content, then what is use of Visible property of content control, if this visible property will work then it will fulfill my requirement. – Surya Mar 28 '17 at 13:02
  • @Fran Have you tried using a `panel` around the `content` to see if it works? See this for a more info [**asp:Content Visible Attribute Ignored?**](https://forums.asp.net/t/1145198.aspx?asp+Content+Visible+Attribute+Ignored+) – Nope Mar 28 '17 at 13:04
  • @Surya The property is inherited from a base class even if Content doesn't use it. So there may be no use. Also I was just asking you to adjust Visible in the master page as an experiment, as stated, not as a solution. – Licht Mar 28 '17 at 15:24

1 Answers1

3

Try this

 mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("Content1");

 mpContentPlaceHolder.Visible=False;
Ricky007
  • 127
  • 8