Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to check if CMSEditableRegion has contents or not? View modes: 
User avatar
Member
Member
ranjan.kumar-thepsi - 1/5/2012 4:59:35 AM
   
How to check if CMSEditableRegion has contents or not?
I have created a custom webpart consisting multiple 'CMSEditableRegion'
<cms:CMSEditableRegion ID="editableHeading" runat="server" RegionType="HtmlEditor"
DialogHeight="30" RegionTitle="Heading" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar" />

On which event and how i will check if this CMSEditableRegion has content ?

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/5/2012 6:31:13 AM
   
RE:How to check if CMSEditableRegion has contents or not?
Hello,

You can check it in the Page_Load event and the code could be like the following one:
protected void Page_Load(object sender, EventArgs e)
{
GeneralConnection gc = ConnectionHelper.GetConnection();

string content = CMS.PortalEngine.PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, CMSContext.CurrentAliasPath, CMSContext.CurrentPageInfo.DocumentCulture, null, true, gc).EditableItems["editableHeading"];

if (content != null)
{
// editableHeading editable region has a content
}
else {
// editableHeading editable region is empty
}
}

Best regards,
Jan Hermann

User avatar
Member
Member
ranjan.kumar-thepsi - 1/5/2012 7:32:56 AM
   
RE:How to check if CMSEditableRegion has contents or not?
I tried following one :
GeneralConnection gc = ConnectionHelper.GetConnection();

string content = CMS.PortalEngine.PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, CMSContext.CurrentAliasPath, CMSContext.CurrentPageInfo.DocumentCulture, null, gc.IsOpen()).EditableItems["editableHeading"];

But it is always giving null...

Design of webpart is as follows:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="3RowsNews.ascx.cs" Inherits="CMSWebParts_TAC_3RowsNews" %>
<li>
<p>
<strong>
<cms:CMSEditableRegion ID="editableHeading" runat="server" RegionType="HtmlEditor"
DialogHeight="30" RegionTitle="Heading" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar"
InheritContent="true" />
</strong>
</p>
<p class="fixedHeightText">
<cms:CMSEditableRegion ID="editableContent" runat="server" RegionType="HtmlEditor"
DialogHeight="80" RegionTitle="Content" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar"
InheritContent="true" />
</p>
<div class="activity-news-image">
<cms:CMSEditableRegion ID="editableImage" runat="server" RegionType="HtmlEditor"
DialogHeight="80" RegionTitle="Image" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar"
InheritContent="true" />
</div>
</li>

Code behind is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.PortalControls;

public partial class CMSWebParts_TAC_3RowsNews : CMSAbstractWebPart
{

protected void Page_Load(object sender, EventArgs e)
{

}
protected void Page_Init(object sender, EventArgs e)
{
this.editableHeading.ID = "Heading_" + this.ID;
this.editableContent.ID = "Content_" + this.ID;
this.editableImage.ID = "Image_" + this.ID;
}
}

User avatar
Kentico Support
Kentico Support
kentico_janh - 1/5/2012 8:08:26 AM
   
RE:How to check if CMSEditableRegion has contents or not?
Hello,

That's because you change their IDs before you call the GetPageInfo function, so please change that line to:
string content = CMS.PortalEngine.PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, CMSContext.CurrentAliasPath, CMSContext.CurrentPageInfo.DocumentCulture, null, true, gc).EditableItems[this.editableHeading.ID];

Best regards,
Jan Hermann