views:

43

answers:

1

I want to have a property on my custom control that is an interface type. For example:

[
    ToolboxData("<{0}:MyTextBox runat=server></{0}:MyTextBox"),
    ParseChildren(true, "Validation")
]
class MyTextBox : WebControl
{
    [
        Category("Behavior"),
        Description("The validation to use"),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
        PersistenceMode(PersistenceMode.InnerDefaultProperty)
    ]
    public IValidation Validation { get; set; }
}

Then when I go to use my control in a web form I would like to be able to do:

        <my:MyTextBox ID="txt" runat="server">
            <my:FancyValidator  />
        </my:MyTextBox>

That way I will be able to define one class that could use any number of validators. When I try and do this now, I end up with an error saying:

Type 'IValidator' does not have a public property named 'FancyValidator'

What do I need to do to make this work?

Thanks!

A: 

Honestly, the easiest thing to do would be to set the property in the code-behind instead of in the markup.

Andrew Hare
True, I definitely could go that route. At the same time, now I want to figure out how to do it this way :)
Jereme
I understand - just thought I would point it out :)
Andrew Hare
As a side note, I found that I can make this work if I make Validation of type List<Validation> then the markup looks like this: <my:MyTextBox ID="txt" runat="server"> <Validation> <my:FancyValidator /> </Validation> </my:MyTextBox>Not quite what I'm after. If all else fails may have to roll with it ...
Jereme