asp:Content 使用 Visible="False" 时仍然可见

asp:Content still visible when using Visible="False"

我有一个母版页,里面有几个 ContentPlaceHolder,并添加了这个母版页的一些内容页。

我想在某个页面的一个 asp:Content 上设置 Visible="False",但它不起作用,因为我仍然可以查看两个 asp:Content 控件的数据。

为什么?

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>

试试这个

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

 mpContentPlaceHolder.Visible=False;