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

Forums / Developing with Sitefinity / Fill generic content content by default

Fill generic content content by default

4 posts, 0 answered
  1. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    04 Nov 2009
    Link to this post
    Hello all,

    I created a custom control (DLL) based on your article "How to wrap a Generic Content control in 3.6 SP1"
    Now I wonder if it is possible to set the content of the generic content on generating the content on a page of sitefinity for the first time.
    Lets say we make a default text like: "The service of the Telerik support team is great"
    Then when dropping the control on a sitefinity page the text within the radeditor would be:
    "The service of the Telerik support team is great" A user can modify it but there is some text in default.

    Please help

    p.s. Indeed The servic of the Telerik support team is great. 
     
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    04 Nov 2009
    Link to this post
    Hi Mart,

    First of all, thank you for the nice words.

    Here's the solution to your inquiry. 

    1. Create a new class in the App_Code directory, named CustomGenericContentCtrl.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Engine.WebControls;
    using System.ComponentModel;
    using Telerik.Cms.Engine.WebControls.Design;
    using Telerik.Framework.Web.Design;
     
    namespace Sitefinity.Samples
    {
        /// <summary>
        /// Summary description for CustomGenericContentCtrl
        /// </summary>
        [ToolboxItem(typeof(CustomGenericContentCtrl))]
        [ControlDesignerAttribute("Sitefinity.Samples.CustomGenericContentDesigner, App_Code")]
        public class CustomGenericContentCtrl : GenericContent
        {
            string defaultText = "Thank you for the nice words!";
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
                if (base.IsEmpty)
                {
                   // writer.Write(defaultText);
                    base.Content = defaultText;
                    base.ViewState["Content"] = defaultText;               
                }
                base.Render(writer);
     
            }
             
        }
     
        public class CustomGenericContentDesigner : GenericContentDesigner
        {
           string defaultText = "Thank you for the nice words!";
            protected override void InitializeControls(System.Web.UI.Control viewContainer)
            {
                base.InitializeControls(viewContainer);
                if (this.DesignedControl.Content.Length.Equals(0))
                {
                    this.Container.TextEditor.Text = defaultText;
                }
            }
     
            public override Type AssemblyInfo
            {
                get
                {
                    return typeof(GenericContentDesigner);
                }
                set
                {
                    base.AssemblyInfo = value;
                }
            }
            public override Type LocalizationAssemblyInfo
            {
                get
                {
                    return typeof(GenericContentDesigner);
                }
                set
                {
                    base.LocalizationAssemblyInfo = value;
                }
            }
        }
    }

    2. Register the new control in the web.config file, section <toolboxControls>
    <toolboxControls>
      <clear />
      <add name="Custom GenericContent" section="Most popular" type="Sitefinity.Samples.CustomGenericContentCtrl, App_Code" />

    The control will be now visible in the Most popular section. 

    Note the variable string defaultText = "Thank you for the nice words!"; This is what will be shown if the control is empty. It will be visible both on the page (done by public class CustomGenericContentCtrl : GenericContent)
    and in the editor (done by public class CustomGenericContentDesigner : GenericContentDesigner).

    Let me know if we can do anything else for you. 

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    04 Nov 2009
    Link to this post
    Hello,


    is there a way to set a template for this text. I would like to make a few templates the user can edit in the radedit content as for example 3 columns, images etc. 
  4. Mart
    Mart avatar
    66 posts
    Registered:
    10 Aug 2006
    05 Nov 2009
    Link to this post
    Hello,


    is there a way to set a template for this text. I would like to make a few templates the user can edit in the radedit content as for example 3 columns, images etc. 
Register for webinar
4 posts, 0 answered