Wednesday, March 21, 2007

A cool un(der)documented feature of ASP.NET 2.0

A few days ago, by way of this bug report, I have learned about a cool ASP.NET 2.0 feature which allows one to extend the Page directive with custom attributes. It is briefly described in this blog entry, but I have investigated the matter a bit farther and discovered a few more details about the feature, see the description below.

Extended attributes are supported for both the Page and the Control directives. If your page inherits from a certain base type, by specifying the parent class name in the Inherits attribute, you can assign any public field or property in the base type by specifying its name in the directive attributes, like so:

<%@Page CustomAttribute="My text" Inherits="BasePage" %>
<%@Control CustomAttribute="My text" Inherits="BasePage" %>

The value of the attribute can be anything the field/property type can be converted to. The conversion is done using the TypeConverter class, with the help of TypeDescriptor class.

As of svn revision 74734, the support for all of the above is in Mono.

No comments: