views:

479

answers:

3

The question was:

I've got a page in a MOSS 2007 publishing site that uses a layout (the page inherits from Microsoft.SharePoint.Publishing.TemplatedRedirectionPage),and I need to write a codebehind for this page, but still let the layout templating mechanism work.

My attempt was to write a class that inherits from Microsoft.SharePoint.Publishing.TemplatedRedirectionPage, and then change the page to inherit from my class. The page behaves normally (i.e., it worked as before), but the methods in my code behind class don't get called.

Anyone know what I should be doing?

But at this point, I'm pretty sure it won't work. My current direction is to try and place a custom server control on the publishing page, but I can't seem to get that working either. Is it just not possible to customize a publishing page except through its layout (which isn't an option here)?

A: 

Okay here is how it works. I belive you got this class Microsoft.SharePoint.Publishing.TemplatedRedirectionPage from a file in the Site Template folder. These pages are just a kind of place holders. Actual pages that get created in the site are not based on the TemplatedRedirectionpage but are of the Instance of the Page Layout that exists in the site.

To solve your Issue you can take

  1. Customize the Page Layout (Inherit the Publishing Page layout class and do the stuff you want) But you said you dont want it.
  2. Second avaliable options is to Create a Ghostable pages using Feature and provision them to the site ( There is a Difference between Ghostable Pages and GhostableInLibrary Pages). How this will solve you issues is that you can write any custom code / Inherit from any class you want and Use a Feature to Provision it. One example for this is to Look at the file 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\sts' and look into the onet.xml for how it is provisioned, C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\SiteTemplates\sts\xml\onet.xml ~163 line Number.
Kusek
A: 

A publishing page is essentially a page layout (template) that has been populated by the end user. Its logic comes purely from the controls that have been added to the page layout. I haven't heard of inheriting from a publishing page class because it shouldn't be necessary - modifying the page layout is the way to do it.

This doesn't really help you if you can't modify the page layout (is there any reason?). I'm not sure what functionality you are trying to add to the page, but here are some ideas:

  • Create a new page layout containing a custom control with the functionality you need and create a publishing page based on that.
  • If you have custom controls used in the page layout already then modify them to give the functionality you require.
  • Investigate delegate controls and see if they will work for you.
Alex Angas
+1  A: 

As it turns out, the most straight-forward way to accomplish what I wanted was to drop a Web Part Zone on the page layout, and then use the SharePoint editing controls to add my control (which can be made into a web part trivially).

All is well, and I didn't have to do anything freaky.

Ben Collins