Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Default value in Custom webpart using CMSEditableRegion control View modes: 
User avatar
Member
Member
ranjan.kumar-thepsi - 1/3/2012 7:27:04 AM
   
Default value in Custom webpart using CMSEditableRegion control
I have created one custom webpart whose code 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" />
</strong>
</p>
<p class="fixedHeightText">
<cms:CMSEditableRegion ID="editableContent" runat="server" RegionType="HtmlEditor"
DialogHeight="80" RegionTitle="Content" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar" />
</p>
<div class="activity-news-image">
<cms:CMSEditableRegion ID="editableImage" runat="server" RegionType="HtmlEditor"
DialogHeight="80" RegionTitle="Image" EnableViewState="false" HtmlAreaToolbarLocation="Out:FCKToolbar" />
</div>
</li>


Now , i want to set some default value to it. Please suggest how can i do this.

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 1/3/2012 12:45:02 PM
   
RE:Default value in Custom webpart using CMSEditableRegion control
I am assuming you want the default content to show only when in Live or Preview mode.

Maybe do something like this (my code will be incomplete, just use it as an example. I also don't know if it will work as I have not tested it)



//expose properties for default values for each editable region
public string editableHeadingDefaultText {get;set}
public string editableContentDefaultText{get;set}
public string editableImageDefaultText{get;set}

override void OnPreRender(EventArgs e)
{
if(this.PageManager.ViewMode == ViewModeEnum.Preview || this.PageManager.ViewMode == ViewModeEnum.LiveSite)
{
//do this for each editable region
if(String.IsNullOrEmpty(editableHeading.GetContent()) && !String.IsNullOrEmpty(editableHeadingDefaultText))
{
editableHeading.Controls.Add(new LiteralControl(editableHeadingDefaultText));
editableHeading.Visible = true; // just in case it's visibility is set to false when there is no content, you can test whether or not you need this on your own
}
}
base.OnPreRender(e);
}

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/4/2012 1:47:50 AM
   
RE:Default value in Custom webpart using CMSEditableRegion control
Hello,

FYI: You could set the default value in CMSSIteManager / Development / Web parts / <e.g. Editable text> / <Default text> if you would use the portal engine. Here you can also add custom properties to each web part.

Best regards,
Boris Pocatko

User avatar
Member
Member
ranjan.kumar-thepsi - 1/5/2012 5:01:01 AM
   
RE:Default value in Custom webpart using CMSEditableRegion control
My custom control consists several CMSEditableRegions and i want to set some default value to each and every CMSEditableRegion .

Please suggest

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/5/2012 10:47:27 PM
   
RE:Default value in Custom webpart using CMSEditableRegion control
Hello,

In that case you will have to handle this scenario as suggested previously in this thread.

Best regards,
Boris Pocatko