The Sitefinity CMS can be easily extended with regular ASP.NET User Controls. Sitefinity will automatically generate input fields for any public properties found in these controls. This empowers content editors to easily modify control properties using only their web browser.
In this example, only the Title property is defined in my user control. The other properties were inherited from the System.Web.UI.UserControl base class.
Using design-time attributes we can hide these properties from Sitefinity. Alternately, we can organize these properties into categories and designate our Title property as the default.
Using Property Categories and Setting Defaults
Design-time attributes are not a Sitefinity-specific feature. These attributes are used by design-time developer tools (such as Visual Studio). Sitefinity, wherever possible, utilizes existing .NET conventions rather than "re-invent the wheel". This prevents developers from needing to learn a new system.
The design-time attributes reside in the System.ComponentModel namespace. Use the Category attribute to set the category for your property and the DefaultProperty attribute to set the focus to a specific property.
Here is a code example:
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
[DefaultProperty("Title")]
public partial class UserControls_CustomControl : System.Web.UI.UserControl
{
private string _title;
[Category("Main")]
public string Title
{
get { return _title; }
set { _title = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Here is the Sitefinity properties' window for this control:
The non-default categories (Behavior & Misc) are collapsed by default. You can hide these properties using the Browsable attribute.
Conclusion
Using a few quick design-time attributes you can make the control properties' window a lot less intimidating. For more information, visit the Managing Properties with Attributes Sitefinity documentation page.
We're not done though. We have more options still available to us. In my next few posts we'll look at Type Editors and Control Designers.