How to hide a content place holder in a .aspx page?


How to hide a content place holder in a .aspx page?



My master page has 3 content place holders:

1. left side bar  2. middle content area  3. right side bar 

So it looks like:

<div id="left"></div> <div id="content"></div> <div id="right"></div> 

On a particular view page (.aspx) that inherits the master page, I want to now show #3 (right side bar).

So I don't want the to be rendered at all.

How can I do this?


Error while parsing a Json object

1:

Can I pass an enum into a controller so the Model Binder binds it?
Ananother thing to consider is nested master pages. Razor/CSHTML - Any Benefit over what we have? [closed] I have a similar design layout I'm doing in a current project, and i have a "base" master page this does all of our script includes, header and footer, and has just a single ContentPlaceHolder this represents everything between the header and footer. Multiple Types of Authorizations in .NET MVC 2.0 We then have a nested master page this uses the base master page, although adds a right "aside" column. Why can't I bind form data directly to action method parameter? For pages where i want the right column visible, i use the nested master page. create a WIKI like “diff” between two strings For pages where i don't want it rendered, i use the base master page.. How to approach unit testing in a large project A strategy like this would definitely prevent your column #3 from being rendered at all (as opposed to being rendered and just being empty, which might not achieve the layout you're going for).. When should functionality be made available in its own Controller? It looks any thing like this:. Base 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">     ...     <asp:ContentPlaceHolder ID="head" runat="server" /> </head>  <body>     <form id="form1" runat="server">         <!-- HEADER -->         ...          <!-- CONTENT -->         <asp:ContentPlaceHolder ID="bodyContent" runat="server" />          <!-- FOOTER -->         ...     </form> </body> </html> 
Nested Master Page. <%@ Master Language="C#" MasterPageFile="~/MasterBase.Master" AutoEventWireup="true" CodeBehind="MasterWithColumns.master.cs" Inherits="MasterWithColumns" %>.
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">     <asp:ContentPlaceHolder ID="head" runat="server" /> </asp:Content>   <asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">     <!-- CENTER COLUMN -->     <div id="centerCol">         <asp:ContentPlaceHolder ID="bodyContent" runat="server" />     </div>      <!-- RIGHT COLUMN -->     <div id="rightCol">         <asp:ContentPlaceHolder ID="rightColumn" runat="server" />     </div> </asp:Content> 

2:

There's a few ways you must achieve this depending on what you mean by "render".. One way is to apply an id to each page's body tag and then use CSS to hide the divs you don't want to be 'rendered' using any thing like.
#myPage #right{display:none;} 
Alternatively, if by 'render' you mean output in the HTML response then you could replace your divs with a partial view. At run time you could then decide which partial views to include in your page, either as part of a base controller this all controllers inherit or as part of each controller individually.. Using a base controller is one of the ways I replicate universalcode in a similar way as you might have done in a master pages codebehind in webforms..

3:

It would be best if you used the content place holders for formatting and placed the actual content inside the .aspx files this inherit from the .master page.. This way you assign your 3 column divs in you master without content although float them left or however you want to format them with your css and use the content reference in your .aspx to place the content into the desired column.. PS. if your looking to create 3 column layout I would suggest using jquerys .ui-layout plug-in instead of endeavor faux columns, etc...

4:

As per the documentation from System.Web.UI.WebControls, you must use the Visible property of the ContentPlaceHolder class.. To did this, you need to go to the CodeBehind file for the webpage. For example:.

Child.aspx

<asp:ContentPlaceHolder id="HideMe" runat="server">     .... </asp:ContentPlaceHolder> 

Child.aspx.vb

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load     HideMe.Visible = false End Sub 
Alternatively, and as pointed out by Jamie Dixon, you must also hide the div with the css rule display:none;.


34 out of 100 based on 34 user ratings 714 reviews