+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Embedding the HTML Content Editor in user control

Embedding the HTML Content Editor in user control

4 posts, 0 answered
  1. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    29 Jul 2010
    Link to this post
    Hello,

    Im trying to display the html editor in a user control so the end-user can input some nicely formatted text, however I don't seem to be getting anywhere fast.

    I've got a user control which looks like:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ServicesSection.ascx.cs" Inherits="lib_controls_ServicesSection" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <asp:Label ID="controlTitleLabel" runat="server" text="Favourite blogs" />
    <sfWeb:GenericContent runat="server" ID="GenericContent1" />

    And then my code-behind which looks like:

    using System;
    using System.ComponentModel;
     
    public partial class lib_controls_ServicesSection : System.Web.UI.UserControl
    {
     
        public string ControlTitle {
     
            get {
     
                if (String.IsNullOrEmpty(_controlTitle)) {
                    return "List";
                }
                    return _controlTitle;
     
            }
            set {
     
                _controlTitle = value;
     
            }
     
        }
     
        [Category("Introduction")]
        [DisplayName("Introduction text")]
        [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")]
        [TypeConverter(typeof(StringConverter))]
        public string Introduction {
     
            get {
     
                return this._introduction;
     
            }
            set {
     
                this._introduction = (string)value;
     
            }
     
        }
     
        //private variables
        private string _controlTitle;
        private string _introduction;
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
     
            controlTitleLabel.Text = ControlTitle;
     
        }
    }

    The error message im getting is:
    Unable to cast object of type 'ASP.usercontrols_phoenix_servicessection_ascx' to type 'Telerik.Cms.IContentContainer'.

    However, im not even really sure I'm implementing this correctly. Can anyone give me any pointers?

    Thanks in advance
    higgsy



  2. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    30 Jul 2010
    Link to this post
    Hi,

    I've actually now got the generic content working, the changes i needed to make were:

    public partial class lib_controls_ServicesSection : System.Web.UI.UserControl, IContentContainer

    And

    [Browsable(false)]
        [Telerik.Cms.Web.UI.WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")]
        [TypeConverter(typeof(StringConverter))]
        public object Content {
     
            get {
     
                return this.GenericContent1.Content;
     
            }
            set {
     
                this.GenericContent1.Content = (string)value;
     
            }
     
        }

    However its not acheived exactly what i want. The RadEditor used in the generic content control has a number of styles / toolbar options that i want to change in this particular control, but i dont want to change the radeditor that is used in the generic content control.

    Is it possible to simply embed a new instance of the RadEditor in my user control, which allows the user to input HTML which is then displayed in a label/literal etc?

    Thanks in advance
    higgsy
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    30 Jul 2010
    Link to this post
    Hello Al,

    This editor HtmlContentEditor is obsolete. Take a look at ContentEditor and More Usable Custom WebEditor

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Al
    Al avatar
    33 posts
    Registered:
    28 Dec 2008
    30 Jul 2010
    Link to this post
    Hi Ivan,

    Thanks for your help.

    I got it working like so:

    public RadEditorSelector()
    {
     
        this.EnsureChildControls();
     
    }
     
    public override string Value {
        get {
            string obj = (string)this.ViewState["ReturnedValue"];
            return (string)editor.Content;
        }
        set {
            this.ViewState["ReturnedValue"] = value;
        }
    }
     
    protected override void CreateChildControls() {
        base.CreateChildControls();
     
        editor = new RadEditor();
        editor.EnableEmbeddedSkins = true;
        editor.ToolsFile = "~/RadEditorSelector.xml";
        editor.ContentAreaCssFile = "~/SiteFinity/ControlTemplates/EditorContentArea.css";
        Controls.Add(editor);
        this.Value = editor.Content.ToString();
    }
     
    private RadEditor editor;

    One last thing though, what CSS/Skins does the RadEditor within the Generic Content use? I dont want my implementation of the RadEditor to look different from the one used as default in sitefinity?

    Thanks for all your help.
    higgsy
Register for webinar
4 posts, 0 answered