views:

203

answers:

2

I have created a custom ASP.NET control ( derived from WebControls.TextBox).

I want to add a property to that control which will be of a type.

This property will actually always be some type of enum . So when in the designer I look at the properties window of that control - I want to be able to assign value to that property by a selection from the specific enum . So I want to see there the list of enumerators from the enumeration that I pass as ..

Example ( not actuall code that will compile .. just to show what I mean):

I have 2 enums :

enum MyEnumABC
{
    A,B,C
}

enum MyColor
{
    Red,Blue,Green
}

I have this control:

 public class MyTextBox<T> : TextBox
{
    public T Classification
    {
        get { }
        set { }
    }
}

Now I create a webpage which have following controls:

<Alex:MyTextBox runat=server id="alex" Classification=MyEnumABC.A></Alex:MyTextBox>
<Alex:MyTextBox runat=server id="alex2" Classification=MyColor.Red></Alex:MyTextBox>

The question is where can I actually pass the type to the constructor of that control ? ( since the page class is the one who calls the constructors of the controls.) Where I actually need to set the type of alex1 to be of MyEnumABC , and the type of alex2 of type MyColor.

And the second question is how I make the VS2008 to support this in the designer of HTML ( so that when I type the Classification in the tag - it will open the write enum for selection of the value) and the property page of the control.

I hope you understand what I mean here.

Thanks .

A: 

The designer will support enum properties without you having to do anything special. Just specify the property in your control's code, give it all the usual attributes to allow it to be displayed in the property window and the property window will automatically display the enum values in a dropdown.

AdamRalph
A: 

AdamRalph : Thanks , but..

I know that property of specified enum type will be supported by the designer . The problem is that my property is of type . I want to assign to it at some point the actual type .( which in my case always some type of enum .. but not the same type).

( I updated the question above to explain myself better )

Alex