Office 365 – SharePoint Online – Classic mode – Adding webpart in custom page layout. Webpart will by default added when new page will created using our page layout

Hi All,

We faced one very wired issue and finally solved it. So thought to share πŸ™‚ It took lots of mine time and research.

Use Case: In SharePoint online classic mode when we need to create new page using our custom page layout, we need OOBweb part (In our case Contacts webpart, here any web part will work) should be available by default on the page.

Background: We have migrated our SharePoint 2013 on-premises site to SharePoint online in classic mode. In SharePoint 2013 we were using feature to associate the web parts to our custom page layouts. So when new pages are created using our custom page layouts those web parts were appearing on the page.

But then this become challenge after migration to SharePoint online in classic mode. We don’t have feature option in SharePoint online. So we have option of editing the page layout adding web part in it and trying. This took the time for me and bit research. Googled bit but no luck soon.

Solution: After bit googled and lots of trial error with page layout, finally found the way.

Here we will take example of Contacts web part since we need to add Contacts web part on our news pages.

We have ContactFieldControl available in Microsoft.SharePoint.Portal assembly and namespace is Microsoft.SharePoint.Portal.WebControls

so we need to add register tag for this assembly in page layout as

<%@ Register TagPrefix="SharePointPortalWebControls" Namespace="Microsoft.SharePoint.Portal.WebControls"
    Assembly="Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Now we need to add WebPartZone in page layout. WebPartZone is available in Microsoft.SharePoint assembly and namespace in Microsoft.SharePoint.WebPartPages

so we need to add register tag for this assembly in page layout as

<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Then we will add web part zone in page layouts as

<WebPartPages:WebPartZone runat="server" Title="Related webpart zone" ID="Related"></WebPartPages:WebPartZone>

Finally, we need to add ContactsField webpart in above webpart zone as

<WebPartPages:WebPartZone runat="server" Title="Aiheeseen liittyvÀÀ -WWW-osa-alue" ID="Related">
            <SharePointPortalWebControls:ContactFieldControl webpart="true" runat="server" 
                Title="Contact Details"

Uploaded our page layout in masterpages gallery and tried by creating new page. It worked like charm πŸ™‚ Existing pages also updated. On all existing pages as well ContactField webpart get added.

Thanks for reading πŸ™‚

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: