Edit: It looks like it might be a Visual Studio issue. If I restart Visual Studio it works until I rebuild the solution.
I'm getting an "'B' could not be set on property 'MyMode'" exception in the designer when using this code:
public class MyControl : CompositeControl
{
public enum MyEnum{ A, B }
[DefaultValue(MyEnum.A)]
public MyEnum MyMode
{
get
{
object obj = ViewState["MyMode"];
return obj == null ? MyMode.A : (MyEnum)obj;
}
set
{
ViewState["MyMode"] = value;
}
}
}
To reproduce: Create the control in a project. Drag the control onto a web form in another project. Set MyMode = B in the properties window. Close the form, reopen the designer.
What am I doing wrong? Do I need to manually parse the string into an enum?
Edit: Designer generated code.
<cc1:MyControl ID="MyControl1" runat="server" MyMode="B" />
Edit: In fact, this property also fails:
public MyEnum MyMode
{
get
{
return MyEnum.A;
}
set{}
}