The Power of PlaceHolders

Everyone knows about the wonders of masterpages and stylesheets but one of the simpler and more prominent components used in SharePoint that is forgotten about is the ASP placeholder controls that power what gets displayed in certain pages, and in certain areas of the page.

As always I am a huge fan of SharePoint designer so I am going to talk about this from the SharePoint Designer perspective (however you can do the same work in Visual Studio or the editor of your choice).

First of all you can edit any of the existing SharePoint placeholders on any page in a number of different ways. The SharePoint Designer supported ways are listed here:

What this means is that it is very easy to customize the individual display of various page elements without having to create new master pages, or large style sheets. This is especially helpful when you have only a few pages that have minor differences. Rather than creating an entirely new masterpage because the structure is different you can just adjust the structure of an individual section of that master page.

Now add the fact that you can create your own placeholders very easily and it basically means you can create one master page that can be dynamic in the sense that it changes based on the page layouts and page content, since the page layouts and page content can describe the value of the placeholder controls.

Add the following to any of your master pages.
<asp:ContentPlaceHolder ID=“MyVeryOwnPlaceHolder” runat=”server”>

Now add the following to any page layout or directly to the page using SharePoint designer (and the methods described in that linked article)
<asp:Content ContentPlaceholderID=”MyVeryOwnPlaceHolder” runat=”server”>
This is <h1>my</h1> very own <b>placeholder control!<b>

Save and load up your page and you should see the html you put into that place holder appear ONLY in the page where you have the asp:Content overriding the placeholders default content.

You can put anything you want into a placeholder. Maybe a complex control with javascript, a simple message to users, or anything else that makes sense to you. The power of the PlaceHolder is in your hands now. Use it well.

Hope you liked the tip,
Richard Harbridge

Explore posts in the same categories: Feature, SharePoint 2007, Tips and Tricks, Uncategorized

Tags: , , ,

You can comment below, or link to this permanent URL from your own site.

One Comment on “The Power of PlaceHolders”

  1. Corey Dutson Says:

    Just a note: If a page layout has a content section in it that does not appear in the master page, you will get an error from SharePoint.

    As a general rule, it’s better to have all of the placeholders on the page (hide the non-required ones in an asp:panel with visible=false or what have you) then to have only the bare minimum.

    One project I’m working on only allows me to use one masterpage, despite differing layouts. As a result I have to make sure I have all of the place holders i need, even if I end up having to hide portions of them with CSS.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: