Add Custom UserControls Registered in the Toolbox using Code

Posted by Community Admin on 03-Aug-2018 09:22

Add Custom UserControls Registered in the Toolbox using Code

All Replies

Posted by Community Admin on 10-Aug-2010 00:00

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 

Posted by Community Admin on 10-Aug-2010 00:00

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

Posted by Community Admin on 11-Aug-2010 00:00

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?

Posted by Community Admin on 11-Aug-2010 00:00

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

Posted by Community Admin on 12-Nov-2010 00:00

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

Posted by Community Admin on 12-Nov-2010 00:00

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

Posted by Community Admin on 12-Nov-2010 00:00

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?.

Posted by Community Admin on 12-Nov-2010 00:00

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.

Posted by Community Admin on 12-Nov-2010 00:00

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

Posted by Community Admin on 23-Nov-2010 00:00

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

Posted by Community Admin on 23-Nov-2010 00:00

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

Posted by Community Admin on 23-Nov-2010 00:00

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

Posted by Community Admin on 23-Nov-2010 00:00

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

This thread is closed