ASP.NET User Control Property Value Options In Designer Mode
Asked Answered
S

3

10

I am using Visual Studio 2008 | .NET 3.5 | C#. I have created an user control that has the following property: DisplayMode. DisplayMode is meant to either display a series of text boxes or a single text box.

[Browsable(true),
Category("Appearance"),
DefaultValue(DISPLAY_MODE_FIELDS),
Description("Indicates whether to display the phone number as a single text box or separate fields.")]
public string DisplayMode
{
      get { return mDisplayMode; }
      set { mDisplayMode = value; }
    }

Therefore, I want the options of the property to either be 'Fields' or 'Single'. I specified above I want to make this browsable in the designer, but how do I set those two values as options rather than knowing to specify 'Fields', 'Single', etc. in the future? Is there another attribute that I can decorate the property with to list these options out or do I need to create an enum (which works)?

Thanks in advance and please let me know if you need any other info!

Sloop answered 2/6, 2009 at 20:22 Comment(0)
N
11

The enum is the way to go. It will provide IntelliSense for the values in the Visual Studio HTML editor, and it will be more type-safe and easier to use in the code.

Nasturtium answered 2/6, 2009 at 20:37 Comment(1)
Thanks for the reply! Sounds good. Didn't know if .NET provided another attribute for this.Sloop
C
11

Just create an Enum

In your user control -

    public enum OrientationOption
    { 
        Horizontal,
        Vertical
    }

    public OrientationOption Orientation { get; set; }

That's it ! this is how it will look like in your VS autocomplete
Auto complete options in code view

Charmainecharmane answered 23/2, 2012 at 15:32 Comment(0)
C
2

I would create a enum for the DisplayMode attribute of your user control

Ceric answered 2/6, 2009 at 20:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.