Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CS Nuglet: Using Master.ascx to display content on selected pages

This came up in at least two Community Server Forums posts today, so it seemed a good Nuglet topic.  What we want to do is add an item to the Master Page Template (Master.ascx) to display on every site page, but we want to be able to turn it off if we want to.  (A lot of this is going to change in Community Server 3.0, but let's live for the day, shall we?)

The Master Page model works on the principle that derived page templates contain MPContent areas that correspond to MPRegions located in the Master Page template.

Here's an example of an MPContent area in the Aggregated Blogs Master Page BlogMaster.ascx and its corresponding MPRegion in Master.


"bhcr" MPContent area in BLOGMASTER.ASCX

<CS:MPContent id="bhcr" runat="server" >
<CS:GenericControl SkinName = "blogs/Skin-AggregateHeader.ascx" runat="Server" id="AggHeader" />
</CS:MPContent>

Corresponding "bhcr" MPRegion in MASTER.ASCX

<CS:MPRegion id="bhcr" runat="server" >
<CS:TitleBar runat="server" id="t" />
</CS:MPRegion>


If Blogmaster.ascx or any template does not contain a "bhcr" content area, the Master.ascx "bhcr" region is displayed on the page.

If an item is added to Master.ascx and not placed in a defined region, it will display on every page without any ability to override it.  For this reason we always want to put new content in a new Master.ascx MPRegion.  Additionally, content added to existing Master.ascx regions like "rcr" (Right Content Region) will be overwritten by the "rcr" Content Area defined in the derived page templates.

Our new Master Page item is a simple "Yousa!"   We're going to place this in a new Master.ascx MPRegion called "pappy."


 

<CS:MPRegion id="pappy" runat="server" >
Yousa!
</CS:MPRegion>


We know we're going to have happy site members with a constant Yousa! happening, but they won't be real happy when they go to add a file attachment to a new blog post and see a "Yousa!" on the modal popup window.  So here's the trick, we override the Master.ascx MPRegion with a MPContent area in the modal popup window.

The modal window in the Control Panel to add attachments to blog posts uses /controlpanel/blogs/attachment.aspx.  Attachment.aspx uses the ControlPanelModalMaster.ascx template.  We know this by looking at attachment.aspx HTML source.

 

<CS:MPContainer runat="server" id="MPContainer" ThemeMasterFile="ControlPanelModalMaster.ascx" IsModal="true">
   <CS:MPContent id="bcr" runat="server">
      <Blogs:UploadAttachment id="UploadAttachment" runat="server"></Blogs:UploadAttachment>
   </CS:MPContent>
</CS:MPContainer>


We need to blank out the pappy region in ControlPanelModalMaster.ascx. We do this by replacing the "pappy" Master.ascx area with our own MPContent area.


<CS:MPContent id="pappy" runat="server" />

The power of Master Pages, in the hands of mere mortals.  Welcome to the world of Community Server!

Comments (2) | Post RSS RSS comment feed

Posted on 11/1/2006 9:40:20 PM by Dave Burke
Categories: Community Server
Tags: No tags for this post

Related posts

Comments

11/2/2006 7:37:06 AM Permalink

I don't think I can explain exactly how confused I now am. I guess now I have to deal with 3 different pages in order to not get my menu to not show up on the attachments windows:
Masters\Master.ascx requires:

Masters\ModalMaster.ascx requires:

Skins\skin-customMenu.ascx Requires: nothing. the file contains this:
<%@ Control Language="C#" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Import Namespace="CommunityServer.Components" %>

I am sooooo confused

macaroo |

11/2/2006 8:39:15 AM Permalink

Put in a Master.ascx region.  Add to the .ascx that it used for pages you don't want it.  That's the crux of the thing.

daveburke |

Comments are closed

This site was built with the Sueetie .NET Online Community Framework. Learn more about Sueetie at Sueetie.com.