Custom default page - edits not saved in content editor web part
-
06-12-2019 - |
Вопрос
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 'Site Actions' button<br/>2. Click on the option 'Edit Page'</p></div>
]]></Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
</WebPartPages:ContentEditorWebPart>
</ZoneTemplate></WebPartPages:WebPartZone>
Решение
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 'Site Actions' button<br/>2. Click on the option 'Edit Page'</p></div>";
CEpart.Content = xmlElement;
partManager.AddWebPart(CEpart, "Top", 1);
}
Не связан с sharepoint.stackexchange