views:

364

answers:

2

I have developed an ASP.NET control for which one of the properties is a [Flags] enum. However, I don't seem to be able to specify multiple flags for this property in the ASP.NET control markup. Is there a special syntax to do this or is it just not possible?

+5  A: 

Just seperate the flags by commas.

Test.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Test.ascx.cs" Inherits="Test" %>
<asp:Label ID="lblTest" runat="server"></asp:Label>

Test.ascx.cs

public partial class Test : System.Web.UI.UserControl
{
    public TestEnum MyProperty
    {
        //coalesce was done to be lazy. sorry. haha.
        get { return (TestEnum)(ViewState["te"] ?? TestEnum.One); }
        set { ViewState["te"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        lblTest.Text = MyProperty.ToString();
    }
}

[Flags]
public enum TestEnum : int
{
    One = 1,
    Two = 2,
    Four = 4,
    Eight = 8
}

Test.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<%@ Register Src="~/Test.ascx" TagPrefix="test" TagName="Test" %>
<form id="form1" runat="server">
    <test:Test ID="test" runat="server" MyProperty="Four,Eight" />
</form>
blesh
+4  A: 

Maybe I'm understanding the question wrong, but can't you set the enum value with a comma-separated string.

E.g. if I have this property in my control:

public System.IO.FileOptions Options { get; set; }

The I can set it in the markup like this:

<uc1:MyControl ID="control1" runat="server"
    Options="DeleteOnClose,Asynchronous" />
M4N