Bobby X
asked on
Programmatically hide a ContentPlaceHolder of a Master Page
Hi,
Is there a way to programmatically hide a ContentPlaceHolder of a Master Page during Page_Load of a content page in asp.net using C#? I need to hide a ContentPlaceHolder in a master page from a content page during runtime or during Page_Load of a content page.
Thanks in advance.
Is there a way to programmatically hide a ContentPlaceHolder of a Master Page during Page_Load of a content page in asp.net using C#? I need to hide a ContentPlaceHolder in a master page from a content page during runtime or during Page_Load of a content page.
Thanks in advance.
ASKER
Hi wht1986,
In my master page, I'm getting a red underline on "MyContentHolder" with Intellisense of VS 2008 indicating something's wrong and also a red underline on "SecondLevelMasterPage" in my code-behind page. Please see code below.
Thanks.
In my master page, I'm getting a red underline on "MyContentHolder" with Intellisense of VS 2008 indicating something's wrong and also a red underline on "SecondLevelMasterPage" in my code-behind page. Please see code below.
Thanks.
My Master Page:
<%@ Master Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="MyMaster.master.cs" Inherits="MyMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public partial class MyMasterPage : System.Web.UI.MasterPage
{
public void SetContentVisibility(bool isVisible)
{
this.MyContentHolder.Visible = isVisible;
}
}
</script>
<asp:ContentPlaceHolder ID="MyContentHolder" runat="server"> </asp:ContentPlaceHolder>
My Content Page's directive:
<%@ Page Language="C#" MasterPageFile="MyMaster.master" AutoEventWireup="true" CodeFile="solutions.aspx.cs" Inherits="solutions" %>
My Content Page's code-behind:
public partial class solutions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SecondLevelMasterPage mp = (SecondLevelMasterPage)this.Master;
mp.SetContentVisibility(false);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wht1986,
It works. I'll accept it as solution in a minute. I have another question. If I turn a regular html <DIV ID="myDiv"> tag into a server control by adding the "runat=server" attribute to the tag (DIV), can I use this same approach (same code) to hide this <DIV>? If yes and the code is different, would you please provide the code as well.
Thanks very much in advance.
It works. I'll accept it as solution in a minute. I have another question. If I turn a regular html <DIV ID="myDiv"> tag into a server control by adding the "runat=server" attribute to the tag (DIV), can I use this same approach (same code) to hide this <DIV>? If yes and the code is different, would you please provide the code as well.
Thanks very much in advance.
ASKER
hi wht1986,
I tried the same code for hiding a <DIV>, and it worked.
Thanks very much for all the help.
I tried the same code for hiding a <DIV>, and it worked.
Thanks very much for all the help.
Open in new window