API
Version 7.x > API > EditableText: GetContent not working on LiveSite View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 11/7/2012 1:58:57 AM
   
EditableText: GetContent not working on LiveSite
I have a custom webpart that contains three editabletext webparts.
When I invoke the method GetContent, I get always null.
Moreover, the method GetContent of the CMSControl ucEditableText (inside the webpart) returns null.
The following code fixes the issue, but i'd like not to use it:

var x = ucEditableText.FindControl("ltlContent") as Literal;
if (x != null)
return x.Text;


How can I fix it? I tried to use the CMSEditableRegion, but it loses the current content of the editabletext webparts.

Many thanks
Regards
Emanuele Firmani

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/13/2012 1:39:01 AM
   
RE:EditableText: GetContent not working on LiveSite
Hello,

Please replace your code with following one to get required content:

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


Where eR is an ID of your Editable Region control.

Best regards,
Jan Hermann

User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 11/13/2012 3:39:18 AM
   
RE:EditableText: GetContent not working on LiveSite
It's not working.
This is what I get debugging:


CMSContext.CurrentDocument.DocumentContent.EditableRegions Count = 0
((Literal)WPEditableText.FindControl("ucEditableText").FindControl("ltlContent")).Text "/vp/erechnung/de"


when invoked from the following extension method:


public static string GetEditableContent(this CMSAbstractEditableWebPart WPEditableText)
{
if (!WPEditableText.StopProcessing)
{
if (CMSContext.CurrentDocument.DocumentContent.EditableRegions.ContainsKey(WPEditableText.ID))
{
return CMSContext.CurrentDocument.DocumentContent.EditableRegions[WPEditableText.ID];
}




//var ucEditable = WPEditableText.FindControl("ucEditableText");
//if (ucEditable != null)
//{
// var x = ucEditable.FindControl("ltlContent") as Literal;
// if (x != null)
// return x.Text;
//}

//ucEditable = WPEditableText.FindControl("ucEditableImage");
//if (ucEditable != null)
//{
// var x = ucEditable.FindControl("ltlContent") as Literal;
// if (x != null)
// return x.Text;
//}

//return WPEditableText.GetContent();
}

return null;
}


Why doesn't the basic EditableText webpart return its content when I invoke its method GetContent()???
I'm using a migrated version of Kentico from 5.5 to 7.

Regards
Emanuele Firmani

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/15/2012 7:12:06 AM
   
RE:EditableText: GetContent not working on LiveSite
Hello,

I have tested it and I am getting content as expected. Anyway, there is another approach, how to get a content from PageInfo object:

PageInfo pageInfo = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, CMSContext.CurrentDocument.NodeAliasPath, "en-US", null, true);
if (pageInfo != null)
{
// Get the content
string content = ValidationHelper.GetString(pageInfo.EditableWebParts["editableRegion_ID"], "");
}


Best regards,
Jan Hermann

User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 11/16/2012 12:46:34 AM
   
RE:EditableText: GetContent not working on LiveSite
This way works.
Here is the final version of the extension method:

		  public static string GetEditableContent(this CMSAbstractEditableWebPart WPEditableText)
{
if (!WPEditableText.StopProcessing)
{
PageInfo pageInfo = PageInfoProvider.GetPageInfo(CMSContext.CurrentSiteName, CMSContext.CurrentDocument.NodeAliasPath, "en-US", null, true);
if (pageInfo != null)
return ValidationHelper.GetString(pageInfo.EditableWebParts[WPEditableText.ID.ToLower()], "");
}

return null;
}


In the future versions, may you let the method GetContent() work also when in LiveMode?

Many thanks for your support
Regards
Emanuele

User avatar
Kentico Support
Kentico Support
kentico_janh - 11/20/2012 6:44:29 AM
   
RE:EditableText: GetContent not working on LiveSite
Hello,

Thank you for sharing your code with all of us. I will forward your suggestion to our development department.

Best regards,
Jan Hermann