Wednesday, June 8, 2011

Sharepoint 2010 - Show web part in Master Page !

Displaying a webpart (your own custom made or any of the OOTB ones) in the master page of your site might not be directly supported by the GUI, but requires minimal effort and no coding.

The easiest way is to add the web part to a normal page (not within a zone), open this page in Sharepoint Designer and steal the generated code. This code can then be inserted into the masterpage where you want it displayed, and then finally add the tag prefix in the header of the masterpage to reference the webpart assembly.

Here's an example:

The following code is the generated markup for my SubSiteTitleWebPart.


1
<WpNs0:SubSiteTitleWebPart runat="server" ID="g_d2f29a1f_146b_450e_aec1_81a20e6a9646" Description="My WebPart" Title="SubSiteTitleWebPart" __MarkupType="vsattributemarkup" __WebPartId="{A44A399D-8D5B-419B-B5E2-71BD0B35EC67}" WebPart="true" __designer:IsClosed="false"></WpNs0:SubSiteTitleWebPart>

Take note of the "WpNso" prefix, this is the one that references to the webpart assembly. You will find the reference at the top of the page, looking a little something like this:

1
<%@ Register TagPrefix="WpNs0" Namespace="SubsiteTitleBar.SubSiteTitleWebPart" Assembly="SubsiteTitleBar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f987c92d971a0fb">

Just copy the same tag prefix to the masterpage and you're done!

No comments:

Post a Comment