Why don't all System.Web.UI.WebControl classes with Text properties implement ITextControl?
Posted
by jrummell
on Stack Overflow
See other posts from Stack Overflow
or by jrummell
Published on 2010-04-09T16:19:00Z
Indexed on
2010/04/09
16:23 UTC
Read the original article
Hit count: 449
ASP.NET
|webcontrols
I'm curious why only some System.Web.UI.WebControl
controls implement certain interfaces when they have the same properties of an interface.
For instance, there are plenty of controls that have a Text property but only the following implement ITextControl
:
- Label
- Literal
- DataBoundLiteral
- TextBox
- ListControl
(TextBox and ListControl actually implement IEditableTextControl which implements ITextControl)
TableCell, Button, HyperLink and others don't so I have to write code like this
ITextControl textControl = control as ITextControl;
TableCell tableCell = control as TableCell;
if (textControl != null)
{
textControl.Text = value;
}
else if (tableCell != null)
{
tableCell.Text = value;
}
instead of this
control.Text = value;
Was this a design decision or an oversight?
© Stack Overflow or respective owner