Hi everyone!
I've managed to get the editor working by using the suggested solution
The aspx page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head1" runat="server">
<title>Edit page</title>
<style type="text/css">
/*
EPi.Dialog cover class
*/
iframe.epidialogcoverframe
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
border: 0;
background-color: transparent;
z-index: 10000;
display: none;
}
</style>
</head>
<body>
<form runat="server" id="form1">
<asp:HiddenField ID="hfPageId" runat="server" />
<div>
<asp:TextBox runat="server" ID="txtHeading"></asp:TextBox><br />
<EPiServer:Property DisplayMissingMessage="false" id="ctlHtmlEditor" Width="300" height="400" EditMode="true" runat="server" />
<br />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" Width="83px" /></div>
</form>
</body>
</html>
and in the code behind page
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!IsPostBack)
{
if (Request["epid"] != null)
{
int pageId = Convert.ToInt32(Request["epid"]);
hfPageId.Value = pageId.ToString();
PageData pd = DataFactory.Instance.GetPage(new PageReference(pageId));
string mainBody = pd.Property["MainBody"].Value as string;
string heading = pd.Property["Heading"].Value as string;
// Set value from page data to the property controls
txtHeading.Text = heading;
PropertyLongString oEditor = new PropertyLongString(mainBody);
oEditor.EditorToolOptions = EPiServer.Editor.EditorToolOption.All;
ctlHtmlEditor.InnerProperty = oEditor;
if (!Page.ClientScript.IsClientScriptIncludeRegistered("system.js"))
{
Page.ClientScript.RegisterClientScriptInclude("system.js", ((PageBase)Page).ResolveUrlFromUI("javascript/system.js"));
Page.ClientScript.RegisterClientScriptInclude("system.aspx", ((PageBase)Page).ResolveUrlFromUI("javascript/system.aspx"));
Page.ClientScript.RegisterClientScriptInclude("episerverscriptmanager.js", ((PageBase)Page).ResolveUrlFromUtil("javascript/EPiServerScriptManager.js"));
}
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
// Get the page
int pageId = Convert.ToInt32(hfPageId.Value);
PageData pdCurr = CurrentPage.CreateWritableClone();
PageReference pl = new PageReference(pageId);
PageData pd = DataFactory.Instance.GetPage(pl);
// Create a writable clone for editing
PageData editedPd = pd.CreateWritableClone();
// Get the new value of the properties
string heading = txtHeading.Text;
editedPd.Property["Heading"].Value = heading;
string mainBody = pd.Property["MainBody"].Value as string;
if (ctlHtmlEditor.PropertyValue != null)
{
mainBody = ctlHtmlEditor.PropertyValue as string;
}
else if (Request.Form[ctlHtmlEditor.ID + "$ctl00$" + ctlHtmlEditor.PropertyName] != null)
{
mainBody = Request.Form[ctlHtmlEditor.ID + "$ctl00$" + ctlHtmlEditor.PropertyName] as string;
}
// Save the new values to the page
editedPd.Property["MainBody"].Value = mainBody;
DataFactory.Instance.Save(editedPd, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
// Redirect back to display the page
Response.Redirect(pd.LinkURL);
}
}
But I can't control the editor tool options. It always show all tools despite the code I change the tool options, e.g.
oEditor.EditorToolOptions = EPiServer.Editor.EditorToolOption.All ^ EPiServer.Editor.EditorToolOption.InsertImage ^ EPiServer.Editor.EditorToolOption.InsertDoc;
Has anyone any idea to solve this?
Toan-Hang