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=14.0.0.0, 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=14.0.0.0, 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" 
                __WebPartId="{803C1870-1A38-4946-9CAA-C85707B1E18D}"
                Title="Contact Details"
                Description=""
                PartOrder="2"
                ID="ContactFieldControl1"
                ChromeType="TitleOnly">
            </SharePointPortalWebControls:ContactFieldControl>
            </WebPartPages:WebPartZone>

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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading