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

Forums / Developing with Sitefinity / Add a Generic Content to a User Control

Add a Generic Content to a User Control

7 posts, 0 answered
  1. Justin
    Justin avatar
    16 posts
    Registered:
    21 Oct 2007
    21 Jul 2008
    Link to this post
    Hi all,
    I'm hoping for a pointer on where to start.  The developer guide has a section that seems just like what I need to do but I'm not super familiar with sitefinity or asp.net yet to put it all together.  here's what I want to do:

    Our site layout has a sidebar on the right.  The CSS template we are using has a class called "sidebox" which when applied to a div tag which creates a simple gray box container.  Users can drop a Generic Content control onto the sidebar but then they would need to go into HTML view and create a div wrapper around their content with the class="sidebox" element in order to get the gray box around their text.  Not all text in the sidebar would be in a sidebox.  So I thought it would be a good user experience to wrap the Generic Content control in a customer user control which simply puts the div with the sidebox class around that instance of the Generic Content control.

    I followed, best I could, the example in the user guide, but the result is that I cannot edit the contents of the Generic Content but can only set the properties for it.

    Is this the best approach to do what I'm considering here?  It's on v 3.2 + Sp2 + hotfix.  If there are any examples of this sort of thing please let me know.

    Thanks!
    Justin
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    21 Jul 2008
    Link to this post
    Hello Justin,

    I have attached an example that demonstrates how to achieve the required functionality. Also, you can find a detailed explanation about wrapping GenericContent control in a user control in the Developer Manual.

    Do let us know if this helps.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Justin
    Justin avatar
    16 posts
    Registered:
    21 Oct 2007
    22 Jul 2008
    Link to this post
    Thanks Pepi.  It works great.

    I had followed the instructions in the Developer Guide (the same link you sent) but the control I made didn't work.  I compared to your code and saw that I missed the IContentContainer inheritance on the class.

    Thanks for the help!!
    Justin
  4. NEX
    NEX avatar
    25 posts
    Registered:
    14 Aug 2007
    08 Jul 2009
    Link to this post
    Before I post by question, I noticed that there is an information icon above that states "Before posting make sure your project is using the exact same RadControl version as the one in this thread. This is an old post and the information may be outdated." This is Sitefinity, so I would first have to dif around to see which radcontrols are used in my version of sitefinity but would have to compare to sitefinity 3.X and "X" could be anything and the "X" can make a BIG difference, so this "warning" is completely useless.

    I am having trouble with finding out how to do something and the major differences between the versions makes it very hard to find any answers.

    This thread show a very easy way to create a user control that simply wraps the generic content control in a "div". This does not work in sitefinity 3.6. Is there an equal or easier way in sitefinity 3.6 to do this? Since the CssClass property was taken away from the generic content (even though it still shows up as a possible property, wasting the time of users that of course assume something that exists in the properties would have an actual function)

  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Jul 2009
    Link to this post
    Hi Alfred Pena,

    I suggest that you should take a look at the following KB article -How to wrap a Generic Content control in 3.6 SP1

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. NEX
    NEX avatar
    25 posts
    Registered:
    14 Aug 2007
    09 Jul 2009
    Link to this post
    Thanks, I've taken a look at the link provided. However, I wanted to confirm that the method decribed in that link is the only method that works on Sitefinity 3.6 SP2? It seems overy complex for only wrapping the output of the generic content control in a DIV tag. For instance, the method used further up in this thread uses a very simple user control, like this:

    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>

    <div class="sidebox" style="border: solid 1px red;">

    <sfWeb:GenericContent ID="GenericContent1" runat="server"></sfWeb:GenericContent>

    </div>


    With codebehind:

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

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    #region IContentContainer Members

    [Browsable(false)]

    [WebEditor("Telerik.Cms.Engine.WebControls.HtmlContentEditor, Telerik.Cms.Engine")]

    [TypeConverter(typeof(StringConverter))]

    public object Content

    {

    get

    {

    return this.GenericContent1.Content;

    }

    set

    {

    this.GenericContent1.Content = value;

    }

    }

    public string ProviderName

    {

    get

    {

    return this.GenericContent1.ProviderName;

    }

    set

    {

    this.GenericContent1.ProviderName = value;

    }

    }

    #endregion

    }

    This simple user control actually works in 3.6 SP2, except the "this.GenericContent1.ProviderName = value;" line generates an error when you use the control and type in text into the control and try to set the content, because "value" is null. Commenting out this line makes it work. Though I'm not sure if there are any "hidden" issues doing this.

    Alfred

  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Jul 2009
    Link to this post
    Hi Alfred Pena,

    The code should not produce error when there is no provider set, since Provider name is implemented from IContentContainer interface. The ProviderName property gets or sets the name of the data provider that will be used to retrieve shared content. If the value is empty or null, the default data provider will be used.
    Also, ProviderName can be persisted as a ViewState. By doing so we will ensure that Generic_Content provider will be set as default provider every time you drop the control on a page.

    public string ProviderName 
        { 
            get  
            {  
                object obj = this.ViewState["ProviderName"]; 
                if (obj == null
                    return "Generic_Content"
                return (string)obj; 
            } 
            set { GenericContent1.ProviderName = value; } 
        } 

    Another option is returning  ContentManager.DefaultProviderName.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
7 posts, 0 answered