Welcome to TechNet Blogs Sign in | Join | Help

Unnecessary custom Placeholder controls

Everyday is a good day to learn something new about MCMS 2002.

Today I learned that lots of custom placeholder controls I and others have written are not really necessary! The same functionality can be achieved with the standard Placeholder controls and and a badly documented feature: PresentationTemplates

A PresentationTemplate allows to modify the default behaviour of SingleAttachmentPlaceholderControls and SingleImagePlaceholderControls without actually modifying the PlaceholderControl itself and without the need to create a custom placeholder control. This means that all Placeholder Controls which only modify the presentation mode behaviour of an existing placeholder control can be replaced with this out-of-the box method.

Here is a list of placeholder controls which can replace easily with this method:

How to implement this method? Very easy! The following code changes an SingleAttachmentPlaceholderControl into a FlashPlaceholderControl:

This is how an SingleAttachmentPlaceholderControl is usually embedded in a template file:

<cms:SingleAttachmentPlaceholderControl id="AttPhCtrl1" runat="server" PlaceholderToBind="AttPh" CssClass="ph"></cms:SingleAttachmentPlaceholderControl>

Most of you will have seen this before. Here is now the changed code to convert this into an FlashPlaceholderControl:

<cms:SingleAttachmentPlaceholderControl id="AttPhCtrl1" runat="server" PlaceholderToBind="AttPh" CssClass="ph">
     <PresentationTemplate>
      <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
              codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
              WIDTH=640 HEIGHT=480>
      <PARAM NAME=movie VALUE="<%# Container.AttachmentUrl %>">
      <PARAM NAME=quality VALUE=high> 
      <PARAM NAME=bgcolor VALUE=#000000>
      <EMBED src="<%# Container.AttachmentUrl %>"
             quality=high bgcolor=#000000
             WIDTH="640" HEIGHT="480"
             TYPE="application/x-shockwave-flash"
             PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">

      </EMBED>
      </OBJECT>
     </PresentationTemplate>
</cms:SingleAttachmentPlaceholderControl>

As you can see this is not very complicated. The PresentationTemplateContainer of the SingleAttachmentPlaceholderControl exposes the following properties:

  • AttachmentText
  • AttachmentUrl
  • PlaceholderControl

Using the PlaceholderControl object it is easy to access all other relevant objects, may it be the AttachmentPlaceholder object itself or may it be the Page object of the current page.

There are benefits and drawbacks in using this method:

Benefit: Customization and updates of the code is very easy and does not require a recompile of a custom placeholder control. It does not even require a recompile of the template project as only the ASPX page and not the code behind file needs to be changed!

Drawback: if you have to include this configured placeholder control on multiple templates then I would still use a custom placeholder control to the effort to add this code multiple times.

So for rapid prototyping this is definitly an alternative to get to a quick solution!

A similar PresentationTemplate is also available for the SingleImagePlaceholderControl. Here it exposes the following properties:

  • AlternateText
  • DisplayHeight
  • DisplayWidth
  • ImageUrl
  • NavigateUrl
  • PlaceholderControl
Published Friday, April 02, 2004 5:19 AM by Stefan_Gossner
Filed under: ,

Comments

Friday, April 02, 2004 9:28 AM by Spencer Harbar

# re: Unnecessary custom Placeholder controls

v. useful - is this is the docs <anywhere /> !? - all I could find was the property definition
Friday, April 02, 2004 9:45 AM by SampoSoft .NET Blog

# Unnecessary custom Placeholder controls

Friday, April 02, 2004 5:45 PM by Stefan [MSFT]

# re: Unnecessary custom Placeholder controls

Hi Spencer,

if it would be there I would have known it earlier.
I had a talk with the Developer who implemented this. But this feature came in very late and missed the deadline for being documented.
It was intended to relief the fact that only 3 out of the box placeholder controls are shipped with the product.

Cheers,
Stefan.
Friday, April 02, 2004 6:17 PM by Patrick Gaul

# re: Unnecessary custom Placeholder controls

Stefan, this is a really great little gem that you found. This can save a lot of time.

Thanks..................Patrick
Monday, April 05, 2004 6:12 AM by SampoSoft .NET Blog

# Undocumented PresentationTemplates -Unnecessary custom Placeholder controls

Wednesday, April 28, 2004 4:51 PM by David Liu

# re: Unnecessary custom Placeholder controls

Hi Stefan,

Great info! Although I couldn't get it right...
If I create a new posting with my template, is it supposed to have the attachment (the flash file) pre-selected? Because mine still says "no attachment set", which makes it just a normal single attachment placeholder... Where am I going wrong?
Wednesday, April 28, 2004 6:47 PM by Stefan

# re: Unnecessary custom Placeholder controls

In authoring mode it is a normal Attachment Placeholder control. You need to select the flash file and save the page.
Then - in presentation mode - the flash will be displayed and run rather than shown as attachment.
Thursday, April 29, 2004 9:33 AM by David

# re: Unnecessary custom Placeholder controls

Understood. Thanks!
Thursday, April 29, 2004 10:42 AM by David

# re: Unnecessary custom Placeholder controls

Just one more thing...
How can I make the web form the size of the flash placeholder only? i.e. - not maximized like it is, but only as big as the flash movie itself? Thanks for your help, much appreciated.
Thursday, April 29, 2004 8:38 PM by Stefan

# re: Unnecessary custom Placeholder controls

The size needs to be given at the object tag and embedd tag as shown above.

Cheers,
Stefan.
Saturday, May 22, 2004 4:53 AM by Rushikesh

# re: Unnecessary custom Placeholder controls

How to do this for PDF,Word,PPT's etc
Friday, June 04, 2004 5:50 PM by Stefan

# re: Unnecessary custom Placeholder controls

For PDF: check out the PDF placeholder control. For Word and PPT you might want to render an IFRAME with a SRC pointing to the document URL.

Cheers,
Stefan.
Thursday, June 10, 2004 2:21 PM by Tobias

# re: Unnecessary custom Placeholder controls

Is there any way to avoid the <span>..</span> tags that are inserted around the PresentationTemplate?
Thursday, June 10, 2004 11:07 PM by Stefan

# re: Unnecessary custom Placeholder controls

not easy. You could write a HttpModule which removes them. Or a render method in the template.
Tuesday, June 15, 2004 2:15 PM by Tobias

# re: Unnecessary custom Placeholder controls

Yes - but then I might as well write my own custom placeholder control :-/

I have never understood why Microsoft puts <span>-tags around everything.
Tuesday, September 14, 2004 8:57 PM by SampoSoft .NET

# Undocumented PresentationTemplates -Unnecessary custom Placeholder controls

Wednesday, January 21, 2009 8:04 PM by Opening a &quot;larger image&quot; pop-up in CMS | keyongtech

# Opening a &quot;larger image&quot; pop-up in CMS | keyongtech

New Comments to this post are disabled
 
Page view tracker