Insert a custom webpart in Master page

For an Intranet SharePoint site, I had a requirement to insert a custom Search web part on the Master page, just below the Quick launch section.
Insert a custom webpart in Master page

But we can’t add a webpart zone into Master page, So I used this trick. In master page, there is a content place holder: <asp:ContentPlaceHolder id="PlaceHolderLeftActions " runat="server"></asp:ContentPlaceHolder> , So I placed the SAME ID for my web part zone in the Page layout/Page, So that in run time, The Master Page's content on PlaceHolderLeftActions will be replaced by the content page.

<asp:Content ContentPlaceHolderId="PlaceHolderLeftActions" runat="server">
<WebPartPages:WebPartZone id="g_A66B59618EF44FE89FCE36DA164B9CC5" runat="server" title="Zone 1">

In simple steps:
1. Create a Blank .Aspx page with SPD
2. Just insert the code as per the below screenshot

<asp:ContentPlaceHolder id="PlaceHolderLeftActions " runat="server"></asp:ContentPlaceHolder>

3. Now attach the master page, and then insert the desired webpart.

Same way, If you want to insert a webpart in Master page, you can use the same Technique, insert your own Tag in Master page and replace the content in your content page by assigning the same tag.
<asp:ContentPlaceHolder id="MyTag" runat="server"></asp:ContentPlaceHolder>

1 comment:

Please Login and comment to get your questions answered!

Powered by Blogger.