More in this section

Forums / Developing with Sitefinity / Multiple Generic Content controls in user control?

Multiple Generic Content controls in user control?

7 posts, 0 answered
  1. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    24 Mar 2009
    Link to this post
    I need to make some of the properties of my user control to be edited by the html editor (UI design requirements, don't ask ;-)

    My first approach was trying to insert several GenericContent controls but I can only implement one IContentContainer per class.

    Any ideas on how to approach this?

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    25 Mar 2009
    Link to this post
    Hello Victor,

    A possible solution is to implement the required properties in the user control (the one implementing IContentContainer interface) and then drag and drop the control on the page as many times as you need. Additionally, you should set these properties for each user control instance depending on the UI design requirements. For example:

    1. Implement a property controlling the CSS class of the <div> wrapping Generic Content control:

    .ascx
    <div id="wrapper" runat="server"
        <sfWeb:GenericContent runat="server" ID="GenericContent1" />  
    </div> 

    .ascx.cs
    public partial class Sitefinity_UserControls_Custom_WebUserControl1 : System.Web.UI.UserControl, IContentContainer 
        public string CssClass 
        { 
            get 
            { 
                return cssClass; 
            } 
            set 
            { 
                cssClass = value; 
            } 
        } 
     
        private string cssClass; 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            wrapper.Attributes.Add("class"this.CssClass); 
        } 
    ... 

    2. Drag and drop two instances of the user control.
    3. Set different values for the CssClass property of the two instances.

    Please, describe in details if there is some misunderstanding.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    25 Mar 2009
    Link to this post
    What we need is to put multiple blocks of generic content in the same control.

    Our designers created a series of "content blocks" and I am coding the user controls to implement them. The idea is to make it easy for our customer to put blocks of content following our design without having to edit html.

    For example, one of our content boxes is a "double box" (see pic attached) and our designers have made very clear both boxes must have same height and the buttons at the bottom must be aligned. The layout is done through tables (I know... don't ask). Here is what I am trying to do:

        <table> 
            <tr> 
                <td><asp:Literal runat="server" ID="Box1Title" /></td
                <td>&nbsp;</td> 
                <td><asp:Literal runat="server" ID="Box2Title" /></td
            </tr> 
            <tr> 
                <td width="192" valign="top"
                    <gcw:Content runat="server" ID="Box1Content" /> 
                </td> 
                <td width="14" valign="top"
                    &nbsp; 
                </td> 
                <td width="192" valign="top"
                    <gcw:Content runat="server" ID="Box2Content" /> 
                </td> 
            </tr> 
            <tr> 
                <td valign="top"
                   <asp:HyperLink runat="server" ID="Box1Link" ImageUrl="" Height="18" Width="57" NavigateUrl="" ToolTip="Learn More" /> 
                </td> 
                <td valign="top"
                    &nbsp; 
                </td> 
                <td valign="top"
                   <asp:HyperLink runat="server" ID="Box2Link" ImageUrl="" Height="18" Width="57" NavigateUrl="" ToolTip="Learn More" /> 
                </td> 
            </tr> 
        </table> 
     

    I tried decorating both content properties in my user control with [WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")] but it does nothing, I guess I need something else but the documentation on these attributes says nothing.

  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    26 Mar 2009
    Link to this post
    Hello Victor,

    OK, If I understand correctly you have two properties which should be set through the RadEditor control. If it is so, then you need to create your own property editor (selector) which provides the required functionality. For details on how to achieve this, please, refer to the following KB: Implementing Rich Text Property Editor

    Do let us know if this helps.

    Regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    26 Mar 2009
    Link to this post
    Thanks for the tip.

    I have a problem with the WebEditor decorator, our project has a bunch of vb files in App_Code so I had to create a subdirectory for C# ones (adding corresponding keys to web.config)

    I placed your RichTextEditor in that subdirectory but I get "ArgumentException: Could not find a type for a name". I added subdirectory name to the argument not to avail. Any ideas?

        [Browsable(true)] 
        [WebEditor("NASE.WebControls.RichTextEditor, App_Code")] 
        [TypeConverter(typeof(StringConverter))] 
        public object RightBoxContent 
        { 
            get 
            { 
                return this.Box2Content.Content; 
            } 
            set 
            { 
                this.Box2Content.Content = value.ToString(); 
            } 
        } 
     

    Copied your control to ~/App_Code/NASE and changed namespace to NASE.WebControls



  6. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    26 Mar 2009
    Link to this post
    I figured it out, just created a C# project, put RichTextEditor class in it and copied the compiled assembly to bin folder.
  7. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    30 Mar 2009
    Link to this post
    Hello Victor,

    We are happy to hear that you have managed to solve the issue. Now, we are closing this thread. Please, feel free to open it, if you still have any questions related to this matter.

    Sincerely yours,
    Pepi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered