Adding Properties and Methods to Your Control

Properties, by definition, are characteristics that you can modify at design time. Font color is a good example of a text property. Methods, by definition, are self-contained blocks of code referenced by a name. You can see an example of such a code block in the code in Listing 13.3, in the form of Output.Write(), where Write() is a method of the Output class.

The example in Listing 13.4 demonstrates how to write a control that exposes three custom properties (of type string, integer, and enum) and then uses them to render some custom content based on how the properties are set. The syntax to add a property is as follows:

Listing 13.3. A Class with a Single Property
 public string SomeProperty { ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.