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

Forums / Developing with Sitefinity / New module and toolbox items

New module and toolbox items

8 posts, 0 answered
  1. mjcutter
    mjcutter avatar
    4 posts
    Registered:
    14 May 2007
    07 Aug 2007
    Link to this post
    Hi everyone -

    I've been tasked with building a couple of new modules for SiteFinity. I'm completely new to SiteFinity and indeed to CMS systems, but I'd hope that I was what would be considered a reasonably accomplished programmer (9 years worth of VB, VBA and ASP and 3 of VB.Net / ASP.Net), so it seemed like a simple task.

    I've followed all the instructions from the blogs.sitefinity.com site, downloaded, examined and copied chunks of the code from the sample.contacts example, and it all seemed to be going so well. However, nothing I do can convince the damn thing to show up in the toolbox when I "Edit" an existing page. It shows up fine in the "Modules" admin section, and I can see the output of my ControlPanel and CommandPanel code, but no matter what I do to the code or to web.config, I don't seem to be able to add a new group to the toolbox, or even add my controls to an existing group.

    I hope that's enough for someone to point out the blindingly obvious thing I have missed. I can post a ZIP of the C# code if it will help.

    Thanks in advance
    Michael
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    07 Aug 2007
    Link to this post
    Hello Michael,

    Thank you for trying our product and contacting us. I hope that you will have a great experience with it.

    There are a few things you should do if you want your controls to display in the toolbox. First, in the main class for your module, you have to override the Controls collection and specify a list of the controls that will appear in the toolbox. Here is an example for Blogs module, which has two public controls - PostList & SinglePost:

    Public Overloads Overrides ReadOnly Property Controls() As IList(Of IToolboxItem)  
        Get 
            Return New List(Of IToolboxItem)(New ToolboxItem(2) {New PostListToolboxItem(), New SinglePostToolboxItem()})  
        End Get 
    End Property 


    As you can see, we are calling the constructors of two classes - PostListToolboxItem and SinglePostToolboxItem. For every control that will appear in the public section, you need a class that inherits from Telerik.Web.ToolboxItem. In the constructor of this class, you would just set the name and description of the control in the toolbox:

    Public Class PostListToolboxItem  
        Inherits ToolboxItem  
        Public Sub New()  
            MyBase.New(GetType(PostList))  
            MyBase.DisplayName = Messages.PostList_DisplayName  
            MyBase.Description = Messages.PostList_Description  
        End Sub 
    End Class 

    Note that you are calling the constructor of the base class (Telerik.Web.ToolboxItem) with the type of your public control.
    After you do this for all of the controls that you want to appear in the toolbox, Sitefinity will automatically display them there, under a section with the name of your module. Good luck with your module development. Don't hesitate to ask for anything that is not clear or problematic.
    I can also send you the code in C#, but you mentioned you have VB experience, so...

    All the best,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. mjcutter
    mjcutter avatar
    4 posts
    Registered:
    14 May 2007
    07 Aug 2007
    Link to this post
    Again I'd like to hope that I could convert that, but if you could post it in C# for me that would be very helpful. Thanks!
  4. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    07 Aug 2007
    Link to this post
    Hi Michael,

    Here is the C# code. First chunk of code:

    public override IList<IToolboxItem> Controls  
    {  
        get 
        {  
            return new List<IToolboxItem>(new ToolboxItem[2] { new PostListToolboxItem(), new SinglePostToolboxItem() });  
        }  

    Second chunk:

    public class PostListToolboxItem : ToolboxItem  
    {  
        public PostListToolboxItem()  
            : base(typeof(PostList))  
        {  
            base.DisplayName = "My Name";  
            base.Description = "My Description";    
        }  

    Additionaly, here is a free code converter provided by Telerik: http://www.codechanger.com. It might come in handy.

    Kind regards,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. mjcutter
    mjcutter avatar
    4 posts
    Registered:
    14 May 2007
    16 Aug 2007
    Link to this post
    Hi Slavo -

    That seems to be working nicely - I've got my controls in the list exactly as I'd want. Next problem is that drag/drop onto the page results in a message that says the control does not inherit from System.Web.UI.Control.

    I've been following the tutorial on the blogs.sitefinity.com site, which is where most of the code has come from so far, but is there a completed module anywhere which I can have a look at to avoid asking daft questions here?

    Thanks
    Michael
  6. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    16 Aug 2007
    Link to this post
    Hello Michael,

    Unfortunately, there is no other sample module that you can use, except Contacts on blogs.sitefinity.com. You can have a look at the JobsIntraSite that comes with Sitefinity. In the App_Code directory there is a class that implements the Jobs module, which, however, is an intra-site module and uses user controls. I just looked at the Contacts module and saw that the public controls are not implemented, but the classes are given and they inherit from CompositeControl. Are you sure you have done this in your project? CompositeControl indirectly inherits from System.Web.UI.Control and all public controls in all Sitefinity modules inherit from it. The structure of public contols for your module is similar to that for ControlPanel - they use templates for the appearance. You can have a look at this blog post for more information:
    http://blogs.sitefinity.com/Ivan/Post/07-05-21/building_a_module_for_sitefinity_part_6_anatomy_of_a_web_control.aspx

    Do not hesitate to ask any other questions you may have.

    Kind regards,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. mjcutter
    mjcutter avatar
    4 posts
    Registered:
    14 May 2007
    18 Aug 2007
    Link to this post
    I'm beginning to think perhaps I'm not smart enough for all this. Classic ASP was much easier...

    The code you gave me above creates a new PostListToolboxItem which inherits ToolboxItem. That's great, the constructor gets called from the new PostListToolBoxItem() bit and it appears on the Toolbox. I'm not sure where PostListToolboxItem should be inheriting CompositeControl though? This is what I have so far:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Telerik.Web;

    namespace Test.Testing.WebControls

    {

    class ProductList : ToolboxItem

    {

    public ProductList()

    : base(typeof(ProductList))

    {

    base.DisplayName = "My List";
    base.Description = "List of stuff for selected company";

    }

    }

    }

    Now I obviously can't change it to class ProductList : CompositeControl
    because then the thing won't compile. I'm sure this is blindingly obvious, but please, what am I not doing here?

  8. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    20 Aug 2007
    Link to this post
    Hello Michael,

    Maybe I wasn't clear enough in my previous answers, I'm sorry. The situation is like this:
    - You need one class for the control itself, which should inherit from CompositeControl.
    - You need another class, that inherits from ToolboxItem, which allows your control (the previous class) to be displayed in the toolbox.

    In the first one, you display the markup for your control by populating its Controls collection. You also provide methods that contain the functionality of your control. It should look something like this:

    public class PostList : CompositeControl  
    {  
         protected override void CreateChildControls()  
         {  
              // create your controls that make up the composite control.  
         }  
         // other methods and properties  

    It is not absolutely mandatory to inherit from CompositeControl. You can implement any kind of Custom Control, by overriding the Render method, for example. I just think that it is easier with a CompositeControl. Here are some articles that you may find useful:
    http://msdn2.microsoft.com/en-us/library/3sf86w5h(VS.80).aspx
    http://msdn2.microsoft.com/en-us/library/aa719735(vs.71).aspx
    http://msdn2.microsoft.com/en-us/library/aa719968(VS.71).aspx

    The second class serves the only purpose to display the control you create above in the toolbox. You set the name and description of the control that will appear in the toolbox. Note that here, in the constructor (line 4), you should give as a parameter the type of your control by using typeof(class_name). In my case class_name is PostList, which is the class name of my control in the first code block. Here is a sample:

        public class PostListToolboxItem : ToolboxItem  
        {  
            public PostListToolboxItem()  
                : base(typeof(PostList))  
            {  
                base.DisplayName = Messages.PostList_DisplayName;  
                base.Description = Messages.PostList_Description;  
            }  
        } 

    I hope this makes it a little clearer.

    Kind regards,
    Slavo
    the Telerik team

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