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

Forums / General Discussions / Add Custom UserControls Registered in the Toolbox using Code

Add Custom UserControls Registered in the Toolbox using Code

13 posts, 0 answered
  1. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    10 Aug 2010
    Link to this post
    Add Custom UserControls Registered in the Toolbox using Code
    I have registered my custom control in the web configuration file. I can drag and drop it nicely in the backend, everything is groovy. Now, my requirements are that I create multiple instances of this control using code and add it to a page template on a page of my choice. Can someone guide me to how I would add custom user controls using code followed by adding property values for the instances of each of the added controls?

    This would help me out greatly!

    Jaime Weise 
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Aug 2010
    Link to this post
    Hi jaime,

    Below is  a sample code that illustrates how to add custom control to a page and set its property.

    public partial class SampleControl : System.Web.UI.UserControl
        {
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                this.Trigger.Click += new EventHandler(Trigger_Click);
                this.Literla1.Text = ShowText;
            }
     
            void Trigger_Click(object sender, EventArgs e)
            {
                var mgr = PageManager.GetManager();
                var pg = mgr.GetPageNodes().Where(t => t.Title == "FirstPage").FirstOrDefault();
                var pageCtrl = mgr.CreateControl<PageControl>("~/Controls/SampleControl.ascx", "E2268733001_Col00");
                ControlProperty prop = pageCtrl.Properties.Where(p => p.Name == "ShowText").FirstOrDefault();
                if (prop == null)
                {
                    prop = mgr.CreateProperty();
                    prop.Name = "ShowText";
                    pageCtrl.Properties.Add(prop);
                }
                prop.Value = "SomeText";
                pg.Page.Controls.Add(pageCtrl);
                mgr.SaveChanges();          
            }
             
            public string ShowText
            {
                get;
                set;
            }
        }


    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    11 Aug 2010
    Link to this post
    It seems I am missing some references. Is this example good for 3.7?

    I see I posted in the wrong forum. Can you transfer this to the other forum or do I need to make another post?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Aug 2010
    Link to this post
    Hi jaime,

    This does not work in 3.x editions. This is code for Sitefintiy 4.0, since the code you forum thread you use is for Sitefinity 4.0.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Venkat
    Venkat avatar
    105 posts
    Registered:
    20 Nov 2008
    12 Nov 2010
    Link to this post
    We are using Sitefinity 4.0 beta version.
    I have added my user controls to the tool box using sitefinity admin tool as described in the below link
    http://www.sitefinity.com/40/help/developer-manual/controls-adding-a-new-control.html
    I have observed that it is updating the file 'ToolboxesConfig.config' .Is there any db changes, it is performing other than these changes?

    But When I try to add the User control to a page,I am not able to see it in the Tool box on the right side of the Page Edit section.
    How can I add it to a page using admin tool by drag drop as we did in sitefinity previous versions.

    Thanks
    Venkat
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    12 Nov 2010
    Link to this post
    Hi Venkat,

    Try registering the control through the UI - Toolboxes section and then restart the application. The control should appear in the widget toolbox after restart.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Venkat
    Venkat avatar
    105 posts
    Registered:
    20 Nov 2008
    12 Nov 2010
    Link to this post
    I have added Image gallery control to a page and published it.
    When I re open the page for editing,I can not edit the control or delete it.
     this is happening to all content control.Is it a bug in sitefinity 4.0 beta vesrion?.

    Download list control not displaying the thumb nails ,How can we display thumb nails.

    we have added the control to the page and set the thumb image too. but it is not showing on the list.Is it a bug or do we need to do some work around to get this?.
  8. Venkat
    Venkat avatar
    105 posts
    Registered:
    20 Nov 2008
    12 Nov 2010
    Link to this post
    Ivan,
    Thank you for you reply.
    Now it is working fine.I think its responding slowly.

    I am able to edit the controls and delete them.

    I successfully added my user control onto the page now.
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    12 Nov 2010
    Link to this post
    Hi Venkat,

    It should not respond slowly if there are just a several documents or images.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. RobertZ121
    RobertZ121 avatar
    64 posts
    Registered:
    14 Aug 2006
    23 Nov 2010
    Link to this post
    Hello Ivan,

    I have the same problem as Venkat, using version 4.0.910.0 - Can you please tell me how to register user controls with the toolbox UI?? 

    Regards Robert
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Nov 2010
    Link to this post
    Hi Robert,

    I attached short video in another thread where I am showing how to register a custom control. The process of registering user controls is the same, but you should enter virtual path for user controls instead of the class library type.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. RobertZ121
    RobertZ121 avatar
    64 posts
    Registered:
    14 Aug 2006
    23 Nov 2010
    Link to this post
    Hi Ivan,

    thanks for support. I could insert one usercontrol. But how can I build a new toolbox. - Does this also work or not? Please look at the attachment.

    Regards Robert
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Nov 2010
    Link to this post
    Hello Robert,

    There should not be a problem to create a new section, but there is an issue when you try to create a page if you do not have a tool in this section.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
13 posts, 0 answered