Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded View modes: 
User avatar
Member
Member
joeh42 - 9/7/2011 8:51:44 AM
   
CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded
I have a Kentico editable text web part on my custom web part. If on a given Kentico page, an editor does not enter any text into the editable text web part, I'd like to hide the web part from the view of end users.

<%@ Register Src="~/CMSWebParts/Text/editabletext.ascx" TagName="editabletext" TagPrefix="uc2" %>
<uc2:editabletext ID="txtDescription" runat="server" RegionType="htmlEditor" DialogHeight="400"
DialogWidth="500" RegionTitle="Description" HtmlAreaToolbarLocation="Out:FCKToolbar" />


I have stepped through debugging and checked the value of txtDescription.GetContent(), but I'm guessing that it's not returning the value that the user enters because it hasn't loaded yet?

Do I need to clone the web part and raise an event at the end of the editable text control function below?

    public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}


Thanks!
Joe Hoppe

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/8/2011 2:50:22 AM
   
RE:CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded
Hi,

you can insert a editable text control into your web part:



<cms:CMSEditableRegion runat="server" ID="MainContentText" RegionTitle="Main text"
InheritContent="true" DialogHeight="320" RegionType="HtmlEditor" HtmlAreaToolbarLocation="Out:FCKToolbar"/>



Then you can get the content of control in a code behind (Page_Load method):



if (CMSContext.CurrentDocument.DocumentContent.EditableRegions.ContainsKey("maincontenttext"))
{
string content = CMSContext.CurrentDocument.DocumentContent.EditableRegions["maincontenttext"].ToString();
}


The ID parameter requires small letter, i.e. instead of MainContentText write maincontenttext.

Now you should be able to check if the control is empty or not.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
joeh42 - 9/8/2011 8:53:32 AM
   
RE:CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded
Hi Ivana,

I've pasted your snippets into my solution and stepped through with the debugger. It's not working and CMSContext.CurrentDocument.DocumentContent.EditableRegions.Count is returning 0, even though there are two editable regions on the page. Do you have other suggestions?

Just to reiterate, I'm trying to have the code, on the public live site, check to see if an admin has entered any content into the editable region. If there's no content, then I want to then hide the editable region.

User avatar
Member
Member
joeh42 - 9/8/2011 9:24:54 AM
   
RE:CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded
Ivana,

I found that CMSContext.CurrentDocument.DocumentContent.EditableRegions.ContainsKey("maincontenttext") won't return true if the editable region doesn't contain any user entered text. Is this by design?

I was then able to check the count to achieve what I need.

It again doesn't count the editable region if an admin hasn't entered any text into it. Is this also by design?

if (CMSContext.CurrentDocument.DocumentContent.EditableRegions.Count == 0)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 9/9/2011 6:28:52 AM
   
RE:CMSWebParts_Text_editabletext.GetContent - returns the editable text for the page? how can I confirm that the control has loaded
Hi,

yes it works as have described. The content of editable text web part/region/images is connected with document and stored in the DocumentContent column in the CMS_Document table. In case the region is not empty, a <region> with web part ID and its content is created. If it is empty a node in xml schema is not created. The methods you mentioned check the content of this column. If all regions are empty, count is 0.

P.S. - be careful when you edit content in the Firefox browser. There was a bug - a Firefox inserts by default <br /> tag into editable text web part, so it could make problems in your code. The <br /> behavior can be removed - it is described in many threads. Or you can check directly the content of fields, if they are really empty or contains <br /> tag.

Best regards,
Ivana Tomanickova