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:
- Create your private member as your Enum:
Private _addedapproved As AddApproveOptions
- Create your property as your Enum:
Public Property AddedOrApproved() As AddApproveOptions
Set(ByVal value As AddApproveOptions)
_addedapproved = value
And that’s it! You should see the little Intellisense box pop up with your options for your new property!