Design Time Support in Custom Server Controls

Visual Studio and ASP.Net provide excellent design time support for all controls. By Design Time support, I am referring to the Values and Description provided in the Properties window when a developer places his focus on the control.

When designing custom server controls, providing such design time support is simple.

[Category(“Custom”)]
[Description(“Set the Corp Image URL.”)]
public string CorpImageURL
{
get
{
return CorpImage.ImageUrl;
}
set
{
EnsureChildControls();
CorpImage.ImageUrl = value;
}
}

Here a property CorpImageURL to set the URL for a Image control is exposed. If the ‘get’ part of the Property is not defined, then the design-time support for the property will not be enabled. So to get the design time support, it is necessary to set the ‘get’ accessor.

The attribute ‘Category’ is used to set the category in which the property will be displayed in the properties window. So in this case, a ‘Custom’ category is defined. If the Properties window is configured to show in the ‘Categorized’ mode, this new Category, ‘Custom’ will be displayed.

The attribute ‘Description’ is used to set the description for the property. The description of the property to instruct what the developer is supposed to provide to the property.

The attribute ‘DefaultValue’ is used to set the default value for the property. Note: This value will be displayed only on the properties window. It will not be assigned to the property by default.

Advertisements

2 thoughts on “Design Time Support in Custom Server Controls

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s