ASP.NET Custom Control With A Property That Is An Interface
Posted
by user129674
on Stack Overflow
See other posts from Stack Overflow
or by user129674
Published on 2010-03-11T20:46:01Z
Indexed on
2010/03/11
20:49 UTC
Read the original article
Hit count: 165
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!
© Stack Overflow or respective owner