More in this section

Forums / Developing with Sitefinity / sharing a user control

sharing a user control

7 posts, 0 answered
  1. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    09 Jan 2009
    Link to this post
    I have noticed that I can share the Generic Content control between several CMS pages.

    I am wondering how I can include this functionality with my own User Control.  I have created a control that will display contact information (name, email, phone number).  This control will be on each page and the same information will be displayed on multiple pages. 

    I had been hoping to create 2 or 3 contact controls and then share them across pages.  With such an approach I will cut down on data entry and maintenance concerns.

    However, being new to SiteFinity I have been unable to figure out where to begin.

    If someone could point me towards some documentation, a blog or an example that would be Fantastic.

  2. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    09 Jan 2009
    Link to this post
    Hi Michael,

    I suppose the easiest method is to simply embed the contact information in the *.ascx file of your User Control.  If you put the contact information directly into this control, it would be displayed each time an instance of the User Control was dragged onto a Sitefinity page.

    Alternately, you could just create a Generic Content control that contains the contact information.  Then use this instead of a custom User Control.

    Do either of these methods work?

    Gabe Sumner
    http://www.sitefinitywatch.com/ 


  3. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    09 Jan 2009
    Link to this post
    The problem with including the details in the user control is that I would have to create a new control for each instance of data.  Instead, I expose properties on the control that allow the user to set the name,email,phone number.  This way the client can take over maintenance once the site is live.

    I discarded the Generic Control because I need to have the style of the control determined by the site theme.  If I use the Generic Control then the user has too much control over layout and styles of the control.

  4. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    10 Jan 2009
    Link to this post
    Got it!

    The Generic Content control is doing its content sharing via a shared repository for its data.  When you create an instance of a GC control, the new control gets saved with a reference ID pointing to the existing data in the database.  (A duplicate of the existing data is not made.)

    So, for example, in your Sitefinity database you have some Generic Content.

    "Here is my content", using an ID of 12345.

    You can then drag & drop 5 instances of the Generic Content control to your pages.  Each of these controls will point to the 12345 ID.  Using this same principal, you can create your own shared content.

    If you're serious about this, it might be useful to research creating a Custom Generic Content Module:  http://www.sitefinity.com/help/developer-manual/adding-new-modules-overview.html

    Gabe Sumner
    http://www.sitefinitywatch.com/

  5. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    10 Jan 2009
    Link to this post
    Hmm, I had been hoping that this would be a feature available through one of the SiteFinity classes.  It seems odd to me that I have to create a whole module to implement the sharing feature when it is available through a generic content control.  Especially since the generic content control doesn't seem to be part of any the 4 standard modules.

    However, if that is how it is done then I have a bunch of reading to do.
  6. Gabe Sumner
    Gabe Sumner avatar
    440 posts
    Registered:
    09 Sep 2007
    10 Jan 2009
    Link to this post
    Actually, almost all the existing Sitefinity modules are Generic Content-based modules.  GC is the foundation for a lot of Sitefinity.

    However, I'll admit building a custom module for your scenario sounds like overkill to me too. 

    Could you just create a User Control with a drop-down selection for "Contact"?  When someone drags an instance of the User Control onto the page they can simply select the correct contact and the contact information would be displayed.  This isn't exactly shared content, but it would prevent multiple controls and allow you to maintain control over the formatting.

    The SF team might have better suggestions than me.  I'm just a monkey with a blog.   :)

    Gabe Sumner
    http://www.sitefinitywatch.com/


  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Jan 2009
    Link to this post
    Hi,

    Well, I am not sure what more we can elaborate on the Gabe's suggestions.

    If you really want to use a functionality which is already implemented, then whatever you do, you will come back to the Generic Content. You can for example create a second provider for Generic Content, and restrict the people to access the content items from it. Then, you can build a user control which takes the content via our APIs. You can take a look at our APIs and the famous GetContent() method. You should have no more than 5-6 lines of code for this. What you win with this approach is that you will still be able to use the RadEditor for your formatting. Then, you can place this control anywhere in your application.
    The other approach is to create a new table in the database, and query the database to take the content. You can also create an external file with the content you need (either plain text or html formatted), and read the data from it every time you need it.

    Sincerely yours,
    Georgi
    the Telerik team

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