Setting properties for ASP.NET Custom Server Controls

The server controls that you see in the IDE are all custom controls only. These are well thought and built by Microsoft and are registered for the IDE. They work very well and interact with each other efficiently.

You can also create such custom control. It is actually a compiled class. The custom control is created programmatically instead of using the IDE’s design page. You can create any complex feature as a custom control and use it on a page. You can define the properties for such a custom server control.

You can use the get and set routines to access the properties and to set them. For example the following code is used to set the property Title in a custom server control.

Public Property Title() As String
Get
Return lblTitle.Text
End Get
Set(ByVal titleValue As String)
lblTitle.Text = titleValue
End Set
End Property

Similarly you can create any number of properties for your custom control. You can also use an attribute called "ToolboxData" to set how it is rendered when the custom control is dragged and dropped in to the designer area. This is used to specify the tag that you want to be displayed and the default value that is to be displayed in the code behind.