Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > CMSHtmlEditor within custom web part View modes: 
User avatar
Member
Member
dima - 1/14/2011 5:26:33 AM
   
CMSHtmlEditor within custom web part
Hello,
I am trying to develop a custom editable web part. And also I try to separate the code from the layout, so I want my ascx file not to have a code behind file at all. Because of that I've done the following:
1. Create a base web part class:
public class BaseWepPart : CMSAbstractEditableWebPart
and overriden LoadContent()
2. Create a class to display the HTML Editor.
public class RichTextTest : UserControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
CMSHtmlEditor editor = new CMSHtmlEditor();
Controls.Add(editor);
}
}

I do understand that that is not enough for a web part for fully functioning - I just tried to keep the code as simple as possible to explain the problem I've faced.

3. The ascx file is:
<%@ Control Language="C#" ClassName="RichTextTest" Inherits="WebToolkit.Server.Controls.WebParts.BaseWepPart" %>
<opc:RichTextTest id='RichText' runat='server' />

When I place the web part on the page it renders "The page cannot be found" error inside the frame that usually renders the editor. Turned out it resolved the url incorrectly: http://localhost/kentico/cms/getdoc/53df6d92-b461-4e32-8829-36f31c10dafa/~/CMSAdminControls/FCKeditor/editor/fckeditor.html?InstanceName=plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_RichText_ctl00&Toolbar=Default

If I go:
editor.BasePath = this.Page.ResolveUrl("~/CMSAdminControls/FCKeditor/");
that fixes the issue I described above. But then I have another problem - when I am trying to insert a hyperlink it opens popup from the location that starts with "/CMSFormControls..." - so it doesn't append the application path as it should like "/kentico/CMSFormControls"

Has anyone had that issue? Please help!

User avatar
Member
Member
dima - 1/17/2011 3:20:08 AM
   
RE:CMSHtmlEditor within custom web part
Ok, after playing a while with different parameters and trying to understand how resolving the urls works in .net I think I've fixed the problem.
What I did I wrote the following:

editor.htmlValue.TemplateControl = this.ParentWebPart;


where the ParentWebPart is RichTextTest from the example above. I think setting this line helps the resolver to find the actual ascx file and then to resolve the url correctly.

just thought i might be usefull to know to somebody.

p.s. just found that you could highlight the code

User avatar
Member
Member
kentico_michal - 1/18/2011 5:50:20 AM
   
RE:CMSHtmlEditor within custom web part
Hi,

I am really glad you found the solution and thank you for letting us know about it.

Best regards,
Michal Legen