Sitefinity CMS

Implementing Simple Functionality of Custom Controls Send comments on this topic.
See Also
Developing with Sitefinity > Controls > Adding New Controls to Sitefinity > Custom Controls > Implementing Simple Functionality of Custom Controls

Glossary Item Box

Custom Controls are quite similar as functionality to User Controls yet there are two important differences:

  • The design-time support should be additionally implemented, if needed.
  • Custom Controls are compiled assemblies (.dll files) and they could be found in the /bin folder of the Web site.

Custom Controls can inherit other classes which gives a developer more control on their behavior.

 

Creating a Custom Control

In order to create a custom control, a separate Class Library project will be created in VS.NET. Figure 1 illustrates what to choose to create a custom control:

Custom Controls - New Library Project

Figure 1

 

Below is a sample implementation of a Custom Control that lists all available Blogs:

C# Copy Code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Blogs;
namespace SampleCustomControl
{
   
public class SampleCustomControl : CompositeControl
   {
       
protected override void CreateChildControls()
       {
           
base.CreateChildControls();
           BlogManager manager =
new BlogManager();
           IList allBlogs = manager.GetBlogs();
           
// add a bulleted list control
           
BulletedList blogsList = new BulletedList();
           
// for each blog add a new list item to the bulleted list
           
foreach (IBlog blog in allBlogs)
           {
               ListItem li =
new ListItem();
               li.Text = blog.Name;
               blogsList.Items.Add(li);
           }
           
this.Controls.Add(blogsList);
       }
   }
}

 

Uploading the Custom Control

To upload a custom control using the Sitefinity UI follow the steps below:

  1. Click to select a page in the Site Map.
  2. Click Edit this page.
  3. Expand the Add Controls toolbox.
  4. Click Upload control situated below the list of all available controls.
  5. The Upload Control dialog opens. Select the Upload a control as .DLL file radio button.
  6. Browse to select the .dll file to upload.
  7. Click I’m done.

 

The groups and the controls from the assembly are automatically inserted into the toolbox.

See Also