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

Forums / Developing with Sitefinity / Controls containing controls

Controls containing controls

15 posts, 0 answered
  1. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    03 Oct 2008
    Link to this post
    Is there any support for allowing a control to contain other controls?  I have two different (but similar) scenarios that I really would like to find a solve for; we're faced with dozens of templates as an alternative.

    1. We would like to be able to place a user control in the middle of a block of custom html created using a generic content; we are pulling custom values from a database to display active statistics, but need the text around these statistics to be editable by any administrator.  (The statistics I'm refering to may or may not be maintained within a Sitefinity module.)  A temporary work-around for this has been creating separate Generic Content controls and placing the user control in the middle, but this does not work well (breaks the admin pretty severely) when trying to style the area containing the user control with divs, etc.

    2. We would like to use ASP.NET's ITemplate properties on a user control to place admin-designed controls inside other controls.  We have creatively-designed sidebars and are currently required to make individual controls for separate contents; it would be greatly preferable to add a "sidebar" object (which has a header area, a body area, and a footer area), and then add controls (such as generic content, flash, or other user controls) to those content areas.

    In standard ASP, we could write our sidebar control as follows:
    <uc:Sidebar runat="server" ID="Sidebar1"
      <Header> 
        My Sidebar Title 
      </Header> 
      <Body> 
        <uc:SwfEmbed runat="server" movie="~/someVideo.swf"/> 
      </Body> 
      <Footer> 
        Provided by ____ 
      </Footer> 
    </uc:Sidebar> 

    Note: the above is an example typed by hand and may be slightly incorrect.

    Unfortunately, we can't find a way to allow this functionality in Sitefinity.  Are we missing something?

    Thanks in advance!
    Matt DeKrey
    TribalDDB
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    08 Oct 2008
    Link to this post
    Hi Matt,

    For your first scenario, your user control should inherit the IContentContainer interface. We have an example with such a control - you can see it at Wrap Generic Content Control in a User Control article.

    If we should be honest, we did not understand completely the second case. We wonder why you do not want to use masterpages and appropriate content place holders inside and drop your controls on them. Could you please try to provide another example or additional details? Yet we suggest you using the masterpages option.

    I hope you find this answer helpful.

    Sincerely yours,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    08 Oct 2008
    Link to this post
    Georgi -

    Actually, your solution for our first case is more like what we want for our second case... but doesn't fit the bill either.  We don't necessarily want HTML in the middle of a user control, but a user control in the middle of the HTML.  For example, a uc:PageViewCounter may simply output in plain text the number of views a page has had, and we may want to put this in the middle of some Html content (a footer for a single page) along with some additional styling.  To keep the PageViewCounter control reusable, we do not want to modify it for this page; in ASP.NET, we would simply write:
    ... lorem ipsum <strong><uc:PageViewCounter runat="server"/></strong> dor amit... 


    For the second case, master pages would work, except that we end up with minor differences between templates and have wound up with over 30 templates on a single project.  What we want to do is better described in an example:

    On your site at http://www.sitefinity.com/product/sitefinity-at-a-glance.aspx you have, on the right-hand side, several of what I would call "sidebars" - the blue, rounded corner content areas.  You have them implemented using your h5 styling on only the "Standard Edition" text, and images in the other two locations.  Outside of sitefinity, we instead have a control (let's refer to it using the ASP.NET code "uc:Sidebar") that allows other user controls to be added to it on an ASP.NET page like this:
    1<uc:Sidebar runat="server"
    2<Contents> 
    3Standard Edition 
    4</Contents> 
    5</uc:Sidebar> 
    6 
    7<uc:Sidebar runat="server"
    8<Contents> 
    9Built with Sitefinity:<br/> 
    10Ryland Homes<br/> 
    11<asp:Image runat="server" ... /> 
    12</Contents> 
    13</uc:Sidebar> 
    14 
    15<uc:Sidebar runat="server"
    16<Contents> 
    17<asp:Image runat="server" ... /> Get Product Updates 
    18</Contents> 
    19</uc:Sidebar> 

    As you can see on lines 11 and 17, we did more than just place HTML content in the sidebar areas.

    Because of the nature of this Sidebar control, it would be ridiculous to put it actually on our Master page; there can be any number or a variable number of those content areas on a page at a time.  (see http://www.sitefinity.com/purchase/buy-now.aspx, where you only have one area that could be considered a Sidebar content area by the definition I've listed above.)

    Our sidebars are much more complex than my example in this post, with both a header and a footer in addition to the main content area.  We would much prefer to have a single "RightSide" ContentPlaceHolder and be able to have as many of our Sidebar controls as we want rather than having 4 templates with 0, 1, 2 or 3 areas where content could go in a "Sidebar".


  4. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    15 Oct 2008
    Link to this post
    Hi Matt,

    Thank you for the additional information. However we still don't understand your concerns.
    Sitefinity does not prevent you using the standard ASP.NET techniques, which means that you can use as many nested controls (WebControls or UserControls ) as you want for your scenario.
    You just cannot put a User Control in the Generic Content control, because it supports only clean HTML content, it doesn't know what to do with tags like "<uc:PageViewCounter runat="server"/>".
    Of course, you could extend the Generic Content control as described in Wrap Generic Content Control in a User Control article and implement a logic for parsing the HTML content (find specific tags and replace them with HTML output).

    As for your second case, probably one of the following approaches could be appropriate:
     - nested master pages;
     - in the code-behind of your master page hide or show sidebars depending on specific conditions;
     - build users controls with sidebars and add them the pages or templates.

    Please let us know if we are missing something.

    Kind regards,
    Vlad
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    15 Oct 2008
    Link to this post
    Thanks for your assistance on the first case.  A custom parser may do what we're looking for; unfortunately, this is a lot more work than we were hoping in order to get the user interface working properly.  We'd already gotten a prototype working for this, but it just felt like we were going about it backwards.

    As for the second case, those were the three solutions we came up with, too.  Unfortunately, all of them require more developer hours than we were hoping we could find a solution for; it just isn't as flexible as our clients are looking for. 

    Thanks once again for your help.
  6. Matt
    Matt avatar
    20 posts
    Registered:
    17 Oct 2008
    02 Dec 2008
    Link to this post

    Funnily enough I'm after this funtionality too, ( the ability to embed dynamic controls within a generic content control ).
    If I understand correctly, the problem is that at runtime the telerik framework would need to understand how to parse and instantiate all the nested controls.

    Is one possible solution to get the framework to just understand the '<asp:placeholder' control, then expose functionality to nest other controls in a placeholder, ( similar to the way the framework deals with the content placeholder within a page ).?

    The runtime / cms data side of things sounds achievable, but integrating this with the admin UI would be fun I imagine.


    Matt M
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    03 Dec 2008
    Link to this post
    Hi Matt,

    Yes, this sounds possible. You can use this approach but we do not provide it our of the box, which means that it will need some development from your side.

    Regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    03 Dec 2008
    Link to this post
    (I'm the first two Matt posts; seems we've got 2 Matt's posting in this thread, and I think we're about to start helping each other... this is going to get confusing.)

    I think the Placeholder control could be useful, but typically those are used for other sorts of things in ASP.NET; the ITemplate interface I think would be much more correct with standard ASP.Net controls. 
  9. Matt
    Matt avatar
    20 posts
    Registered:
    17 Oct 2008
    03 Dec 2008
    Link to this post

    Before getting into what looks like several days of investigation and dev on this. Is there a way to stop the rad editor 'auto closing tags'

    eg if I insert html like this in the rad editor

    <div class="argDivClassLolz">  
     <p> 

    on switching to rad view or editing again
    the rad editor decides to be helpful and adds closing tags
    eg.

    <div class="argDivClassLolz"></div> 
    <p></p

    while this behaviour is generally desireable I'm sure, it would be useful perhaps to be able to set a 'raw mode' on a per control basis.. ie to allow wrapping raw html around other controls, as discussed as a 'workaround' for the nested controls approach. 
    If not I might have to create a 'literal control' ( a generic content container, but without just text boxes to edit the content, instead of the rad editor.


  10. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    04 Dec 2008
    Link to this post
    Hello Matt,

    Unfortunately this is the browsers behavior, not an editor function. The only filter we use is ConvertToXhtml, everything that is changed in the html is coming from the browser.

    Sincerely yours,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  11. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    04 Dec 2008
    Link to this post
    But, isn't that the exact problem Matt M is asking about?  Turning on "Raw Mode" should turn off the call to ConvertToXhtml

    Matt M, I tried working around this by editing the database directly, and got expected results on the view.  HOWEVER, this severely broke the admin tool, and I do not recommend it.  (It uses html, too, of course, and the open tags caused very weird behaviors...)  I had to revert my changes by hand.

    We resorted to making multiple templates; you can check for the Page's Site property to determine if you're in the designer or not.  If you're not in the designer, and your ContentPlaceHolder is still empty after CreateChildControls, set your outer control's property to not display that way you can still edit and not have tons of templates.  It's a hack, but it worked well enough for us.

    I'm still working on other solutions, however, so I'll be sure to post it if I discover anything.

    Matt DeKrey
    TribalDDB

  12. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    05 Dec 2008
    Link to this post
    Hello,

    My point is that ConvertToXhtml is not actually fixing the content by closing the tags. The tags will be closed even in Raw mode by the browser.

    Best wishes,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  13. Matt
    Matt avatar
    20 posts
    Registered:
    17 Oct 2008
    05 Dec 2008
    Link to this post
    Presumably the browser is manipulating it when it's put into the rad control itself or into the page when its presenting it in preview.

    Sounds Like Matt D's approach of not rendering the staged content in the designer is the way to go. Will mean creating a whole module with a textbox editor instead of a rad editor eg the 'html literal module' though :/

    Matt Mercer
  14. Matt
    Matt avatar
    16 posts
    Registered:
    29 May 2008
    05 Dec 2008
    Link to this post
    Matt M -

    I'd be happy to discuss this with you in more detail; contact me via LinkedIn if you're interested.

    Here's the code I'm using to test if it's in normal viewing mode:

    if (Page.Site == null || !Page.Site.DesignMode) 


    Matt DeKrey
  15. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    08 Dec 2008
    Link to this post
    Hi Matt,

    We will definitely take some notes on this feedback and see what can we do further.
    Thank you.

    Sincerely yours,
    Georgi
    the Telerik team

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