2

Following is the code in my page layout.

<WebPartPages:WebPartZone id="page_detail" runat="server" title="Page Detail" PartChromeType="None"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>

Is it possible to add a default web part here so when the page loads, that web part is already there rather than user has to click on "Add a web part" link?

I would like to add Content Editor web part here.

1

I've always done this with SharePoint Designer (SPD) when I needed to accomplish the task. If you have access to SPD, here is the lowdown:

  • Edit the layout in Advanced Mode
  • Make any of the surrounding HTML edits you need and save the layout.
  • Go to Insert tab > click on Web Part Zone
  • I usually hit enter for readability, which means you have to save again.
  • Go to Insert tab > click on Web Part (dropdown) and select the WP you want to insert.
  • Save again.

That should do it. You will wind up with something like this:

<WebPartPages:WebPartZone id="g_A48E6AA09E6A4497AB23C22C6247DBBE" runat="server" title="Zone 1">

                    <WebPartPages:ContentEditorWebPart webpart="true" runat="server" __WebPartId="{4C1491E9-30FA-48A2-80EA-BEB4171B84EC}"><WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
    <Title>$Resources:core,ContentEditorWebPartTitle;</Title>
    <Description>$Resources:core,ContentEditorWebPartDescription;</Description>
    <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
                    <PartOrder>2</PartOrder>
                    <ID>g_4c1491e9_30fa_48a2_80ea_beb4171b84ec</ID>
</WebPart></WebPartPages:ContentEditorWebPart>

                    </WebPartPages:WebPartZone> 

A few things of note: - Saving the layout and coming back into it will populate a few more properties that you can edit, such as Chrome Type. It also provides the content area where you can add pre-populated content to the content editor if you wish. See this Stack post for how that is done.

0

Try to add this code to the page. This works for me in a master page but I didn't try in a page layout

<asp:WebPartManager ID="WebPartManager1" runat="server"/>
    <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
            <WebPartPages:ContentEditorWebPart ID="ContentEditorWebPart1" runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{put your guid here}" >
               <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
                  <Title>Content Editor</Title>
          <FrameType>None</FrameType>
          <Description>Allows authors to enter rich text content.</Description>
          <IsIncluded>true</IsIncluded>
          <FrameState>Normal</FrameState>
          <AllowRemove>true</AllowRemove>
          <AllowZoneChange>true</AllowZoneChange>
          <AllowMinimize>true</AllowMinimize>
          <AllowConnect>true</AllowConnect>
          <AllowEdit>true</AllowEdit>
          <AllowHide>true</AllowHide>
          <IsVisible>true</IsVisible>
          <DetailLink />
          <HelpLink />
          <HelpMode>Modeless</HelpMode>
          <Dir>Default</Dir>
          <PartImageSmall />
          <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
          <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
          <IsIncludedFilter />
          <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
          <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
          <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">PUT YOUR CONTENT HERE</Content>
          <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
              </WebPart>
            </WebPartPages>
        </ZoneTemplate>
    </asp:WebPartZone>

Good Luck

  • Not working in page layout. It is showing error "The control type 'System.Web.UI.WebControls.WebParts.WebPartManager' is not allowed on this page." – Frank Martin Aug 5 '13 at 6:36
  • Did you try to insert just the web part to the web part zone? Sounds like you are trying to copy the web part manager tag along with the rest of the code in this answer – Denis Molodtsov Oct 21 '16 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.