Wednesday, 8 October 2008

User Control Properties with Enum Types

Rather than specifying web user control properties with string type we can have much controlled properties using enums. For example.. I need to create a user control with two command buttons which I should be able to use in few places in a page. Two command buttons should appear horizontally or vertically depending on a property (DrawMode) in the user control.

I have following layout in html

Click to enlarge

Then I can write property as follows in the user control
Click to enlarge
The user of this user control must specify the "Verticle" correctly for this to work. There is no control over the value you can set to the property.

You can enhance this code using an enum as follows


Click to enlarge



The advantage is that you have the total control over the property values that can be assigned.

Click to enlarge

No comments:

Popular Posts