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

Forums / Developing with Sitefinity / Composite control

Composite control

13 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    11 Jun 2007
    Link to this post
    Hello Telerik team

    I want to develop a custom control (composite control) that consist of the generic content control and another custom control x we developed.
    When you drag this composite control to a container field you have the generic content control and the custom control x available directly for management.

    When this is possible you don't have to define different themes in which you must drag the different controls to the specified containers, but you are able to specify the layout in the composite control and drag this to the only defined container.

    Regards
    Luc Baeten
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    12 Jun 2007
    Link to this post
    Hello Luc,

    Could you please clarify your question? It’s not quite clear why you want to include generic content control as a part of your own composite control and what is your question about themes. Using themes is an optional feature and you can use them only if you want; it’s not a problem to control the layout from your control without using a theme. Could you give us an example, describing what you want to achieve so we can figure out how we can help you?

    Thanks in advance for your assistance.

    Kind regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    12 Jun 2007
    Link to this post

    Hello Pepi

    I already developed different websites with Sitefinity. What happens very often when defining a new page in the website is that you have to drag the same controls (generic content, image, custom control) to your page each time again. To make it easier for our customers I was thinking of building a composite control that can be dragged to the page at once. So you only have to drag one control to the page that consists of different other controls. On the other hand you must be able to manage those controls seperately.
    An important part of the composite control is the existence of the generic content control in it.

    I understand the concept of the theme usage. When I am able to define a composite control I can define the wanted layout in this control (or use the theme).

    Kind regards
    Luc

  4. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    13 Jun 2007
    Link to this post
    Hi Luc Baeten,

    The functionality you want can be achieved as follows:

    You need to create a custom control inheriting from Generic Content. You need to inherit from Generic Content if you want to use the web editor to edit the content in your control. In this control, you need to override the Render method to output the desired HTML. You can include any HTML that you wish, and you can call the base class’s Render method that handles rendering the Generic Content. In this way you can output additional HTML before and after the generic control. Here is some sample code demonstrating how to do this:

    1     using Telerik.Cms.Engine.WebControls;  
    2       
    3     [ToolboxItem(typeof(CustomGCToolboxItem))]  
    4     public class CustomGenericContent : GenericContent  
    5     {  
    6         protected override void Render(HtmlTextWriter writer)  
    7         {  
    8             string imgPath = base.ResolveUrl("~/Images/location.gif");  
    9             writer.Write(String.Format("<img src=\"{0}\" /><div>", imgPath));  
    10             base.Render(writer);  
    11             writer.Write("</div><p>Test</p>");  
    12         }  
    13     } 

    In this sample I have output an image, then Generic Content, and then a paragraph with one word. There is one more thing to do to enable your control to work in Sitefinity. You have to implement you own ToolboxItem class that will represent your control in Sitefinity’s toolbox, because the default one uses regular generic content. In my example, the class is called GustomGCToolboxItem, as you can see in the attribute applied to the class in line 3. Here is the class itself:

    1     using Telerik.Web;  
    2  
    3     public class CustomGCToolboxItem : ToolboxItem  
    4     {  
    5         public CustomGCToolboxItem()  
    6             : base(typeof(CustomGenericContent))  
    7         {  
    8             base.DisplayName = "Custom Generic Content";  
    9             base.Description = "Some description";  
    10         }  
    11     } 

    Here you have to inherit from ToolboxItem and just write a constructor for the class. In the constructor, you call the constructor of the base class, specifying the type of your new control, in my case CustomGenericContent. Then you only need to set the name and description of your custom ToolboxItem.
    Now, when you add your control to Sitefinity’s toolbox, you should be able to use it when creating pages.

    All the best,

    Slavo
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  5. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 Sep 2007
    Link to this post
    Hello Slavo

    I defined a Class library with the two classes as you specified. When I compile the library I get the error: 

    The type or namespace name 'ToolboxItem' could not be found (are you missing a using directive or an assembly reference?) 

    on the statement 

        [ToolboxItem(typeof(CustomGCToolboxItem))]

    of my class definition

    using System.Web.UI;
    using Telerik.Cms.Engine.WebControls;

    [ToolboxItem(typeof(CustomGCToolboxItem))]
    public partial class CustomGenericContent : GenericContent
    {

        protected override void Render(HtmlTextWriter writer)
        {
        writer.Write(
    "test<div>");
        base.Render(writer);
        writer.Write(
    "</div><p>test</p>");
        }
    }


    This is the CustomGCToolboxItem class:

    using Telerik.Web;

    public class CustomGCToolboxItem : ToolboxItem
    {
        public CustomGCToolboxItem()
            :
    base(typeof(CustomGenericContent))
        {
            
    base.DisplayName = "Card Generic Content";
            
    base.Description = "Card distribution and text";
        }
    }


    What assembly should I use?

    regards
    Luc
  6. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    19 Sep 2007
    Link to this post
    Hello Slavo

    An addition:

    After using System.ComponentModel I was able to compile the Class library.

    But I am still not able to use the custom generic control. I tried two things:
    1. 1. I added 

      <add name="Card Generic Content" section="Generic Content" type="CustomGCToolboxItem, CMS_BridgeNet_CustomControls" description="Displays the Card distribution and ." />

    to my web.config. I can see the control now in the Toolbox but when I add it to a contentplaceholder the following error is presented: 
        Type 'CustomGCToolboxItem' does not inherit from 'System.Web.UI.Control'.

    2. I tried to add the control via the Upload control functionality. But then I receive the error:
        Type 'CustomGCToolboxItem' does not inherit from 'System.Web.UI.Control'

    So it seems the same problem. Have you any idea what I need to do?

    Hope you can help.

    Kind regards
    Luc Baeten

  7. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    21 Sep 2007
    Link to this post
    Hi Luc Baeten,

    When you write this line in the web.config, you are trying to register the ToolboxItem object instead of the control. So in the type attribute you should have something similar to this: "CustomGenericContent, CMS_BridgeNet_CustomControls". Actually, there might be some other problems as I can see from the code that your control is partial class and is not wrapped in a namespace. That is why I created a small project with the functionality you need. You could add it to your solution and register the control in the web.config in the following way:

    <add name="CustomGenericContent" section="Custom Controls" type="MyNamespace.CustomGenericContent, ClassLibrary1" />

    Hope this helps.

    Greetings,

    Vassil Daskalov
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  8. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    21 Sep 2007
    Link to this post
    Hello Vassil

    Thanks for your information. I started with register the CustomGenericContent class in the web.config. But I couldn't get it to work at that moment. So I tried a lot of other things.

    With your info I have it work. But now I am going a step further :

    In the toolbox I also added a user control (in the web.config <add name="OnePlayer" section="BridgeNet" url="~/UserControls/OnePlayer.ascx" />)

    Now, in the CustomGenericContent class I want to load that user control oneplayer.ascx. So that I have a composite control that is added in the toolbox.

    When I now drag this composite control to the page I want to see the usercontrol and the generic content control both at the same time. And both editable seperately from each other. Because in oneplayer.ascx I have a lot of custom properties that I want to edit. And of course with the generic content I must be able to edit text.

    If that is not possible I could go the other way around: using the usercontrol oneplayer.ascx and add generic content control to it??!!

    I hope you understand what I want.
    Kind regards
    Luc
  9. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    24 Sep 2007
    Link to this post
    Hi Luc Baeten,

    Sorry, I did not see your first posts. Actually, the functionality you want might be achieved with a user control much easier. I created a user control which can be used for adding more controls with only one drag and drop. When it is registered in the toolbox and drag and dropped to the page, it adds all its child controls as separate controls available for direct edit or delete; just the you would add them one by one.

    Please let me know if this is not exactly what you want to achieve.

    Kind regards,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    24 Sep 2007
    Link to this post
    Hi Vassil

    Thank you very much for your info. It starts to work now. I needed to make changes to your CoupleControls.ascx in the following way:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CoupleControls.ascx.cs" Inherits="UserControls_CoupleControls" %>
    <%
    @ Register Src="OnePlayer.ascx" TagName="OnePlayer" TagPrefix="uc1" %>
    <%
    @ Register Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" TagPrefix="gCnt" %>

    <asp:Literal ID="Literal1" text="<div>" runat="server"></asp:Literal>
    <
    gCnt:GenericContent runat="server" ID="genericContent"></gCnt:GenericContent>
    <
    asp:Literal ID="Literal2" text="</div>" runat="server"></asp:Literal>
    <
    asp:Literal ID="Literal3" text="<div>" runat="server"></asp:Literal>
    <
    uc1:OnePlayer ID="OnePlayer1" runat="server" />
    <
    asp:Literal ID="Literal4" text="</div>" runat="server"></asp:Literal>


    Reason for those changes: I want to add a usercontrol and I want to add div's around the generic content control and the user control.

    I have two issues with this code

    1) When I drag the CoupleControls control to a new page the usercontrol shows a message 'Index was outside the bounds of the array.' instead of the output of the control in edit mode. In presentation mode the usercontrol output is correct.

    2) Maybe there is another solution for the div definition because I don't want to see those 4 literals in edit mode.
     
    Kind regards
    Luc
  11. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    25 Sep 2007
    Link to this post
    Hi Luc Baeten,

    Unfortunately, the only solution I see for the divs problem is to add them in the controls. Thus you should use custom generic content control which has the divs included by default. The other divs you should put inside your user control. Perhaps you have taken a look at the code behind of the CoupleControls control. There all the LiteralControls controls are not added to the page as every space between the server controls including the new line character and the html code are transformed into LiteralControl controls and thus add useless information in the page.

    Actually, the div problem would be the same if you are not using the CoupleControls control. How would you add them then?

    The other problem is omission on my side. It's different when you are adding another user control or a custom control with the CoupleControls. And if there is a user control, it is added as a custom control which causes the error. Sorry about that. I am sending you the modified version of the control.

    Greetings,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    25 Sep 2007
    Link to this post

    Hi Vassil

    I used both of the proposed developments together in the CoupleControl.ascx. I used the CustomGenericContent control where I added the div tags. In my own usercontrol I added the div tags too.
    In the CoupleControl.ascx I combined both controls together.
    That works great.

    Thank you very much for your support.

    Regards
    Luc

     

  13. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    26 Sep 2007
    Link to this post
    Hello Luc Baeten,

    Thanks for the nice words. I am really glad that everything works fine now. You know you can always rely on us.

    Sincerely yours,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
13 posts, 0 answered