1

I've created a custom default.aspx page which is provisioned through a custom web template using SharePoint 2010. I've added the below code to add a content editor web part, with some default content. When I try to make edits (edit page - stop editing) I see the changes but they are gone again after a reload or refresh of the page.

When I open the page in SharePoint Designer and save it again. The page works as expected without an issue (edits are visible after reload or refresh).

<WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="WSCenter1" Title="loc:Content Editor Web Part"><ZoneTemplate>
<WebPartPages:ContentEditorWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{4CF1E63D-4498-4B9D-BD1D-273A9550BFA8}" >
<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>
  <PartOrder>2</PartOrder>
  <FrameState>Normal</FrameState>
  <Height />
  <Width />
  <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/images/mscontl.gif</PartImageLarge>
  <IsIncludedFilter />
  <ExportControlledProperties>true</ExportControlledProperties>
  <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
  <ID>g_4cf1e63d_4498_4b9d_bd1d_273a9550bfa8</ID>
  <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
  <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[<div style="border-bottom: #dbdbdb 1px solid; border-left: #dbdbdb 1px solid; padding-bottom: 10px; padding-left: 10px; width: 740px; padding-right: 10px; height: 200px; border-top: #dbdbdb 1px solid; border-right: #dbdbdb 1px solid; padding-top: 0px"><p style="color: #003365; font-size: 18px; font-weight: normal">
    ​Welcome to this newly created Site!</p>
<p>You can update this content by following the below steps:<br/>1. 
Click on the &#39;Site Actions&#39; button<br/>2. Click on the option &#39;Edit Page&#39;</p></div>
]]></Content>
  <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
</WebPartPages:ContentEditorWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>
2
  • After page refreshing what do you see? Empty content or previous(old) content? Jan 10, 2012 at 16:54
  • I see the initial/previous content. E.g. I add more text, I click on stop editing I see my text update but than when I refresh the update is gone and my initial text is shown again...
    – Wim Hill
    Jan 11, 2012 at 6:22

1 Answer 1

1

I used the following workaround which suits me. I removed the above code from mu custom default page and just left a web part zone:

<WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Top" Title="loc:Editable Content Top" />

To provision the page with my Content Editor I use the below code behind after my new site is created:

public static void ProvisionHomePage(SPWeb web) {

                string RootUrl = web.Url;
                SPFile file = web.GetFile(RootUrl + "/" + "default.aspx");

                SPLimitedWebPartManager partManager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                ContentEditorWebPart CEpart = new ContentEditorWebPart();

                CEpart.Title = "Welcome Content Editor Part";
                CEpart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;

                // Create an XmlElement to hold the value of the Content property.
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement xmlElement = xmlDoc.CreateElement("MyElement");
                xmlElement.InnerText = "<div style=\"border-bottom: #dbdbdb 1px solid; border-left: #dbdbdb 1px solid; padding-bottom: 10px; padding-left: 10px; width: 740px; padding-right: 10px; height: 200px; border-top: #dbdbdb 1px solid; border-right: #dbdbdb 1px solid; padding-top: 0px\"><p style=\"color: #003365; font-size: 18px; font-weight: normal\">​Welcome to this newly created Workspace!</p><p>You can update the content of this box by following the below steps:<br/>1.Click on the &#39;Site Actions&#39; button<br/>2. Click on the option &#39;Edit Page&#39;</p></div>";

                CEpart.Content = xmlElement;
                partManager.AddWebPart(CEpart, "Top", 1);       
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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