ASP.NET: Create a User Control Property with Selectable Options
I guess I’ve always taken those little options for granted whenever I want to pick something in a control, say what mode to put a textbox in (text, multiline, or password), because when I wanted to add something similar for a user control, I had no idea how to do it. Thanks to the friendly and extremely helpful people at StackOverflow, I was able to grok the answer.

Here’s the scenario: you have a user control in your .aspx page with one property, say “addedorapproved” as in the above image. You want the options “Added” and “Approved” to show up as your selectable options. To do so, you must complete the following steps:
- Create an enum with your available options:
Enum AddApproveOptions
Added
Approved
End Enum - Create your private member as your Enum:
Private _addedapproved As AddApproveOptions - Create your property as your Enum:
Public Property AddedOrApproved() As AddApproveOptions
Get
Return _addedapproved
End Get
Set(ByVal value As AddApproveOptions)
_addedapproved = value
End Set
End Property
And that’s it! You should see the little Intellisense box pop up with your options for your new property!
RSS Feed
Thank you so much for this tutorial. I’ve been looking for this since forever. Works great!!
Glad I could help!
Ну ты даёшь!
C# version
In your user control -
public enum OrientationOption
{
Horizontal,
Vertical
}
public OrientationOption Orientation { get; set; }