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:

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:
- Click to select a page in the Site Map.
- Click Edit this page.
- Expand the Add Controls toolbox.
- Click Upload control situated below the list of all available controls.
- The Upload Control dialog opens. Select the Upload a control as .DLL file radio button.
- Browse to select the .dll file to upload.
- Click I’m done.
The groups and the controls from the assembly are automatically inserted into the toolbox.
See Also