Why don't all System.Web.UI.WebControl classes with Text properties implement ITextControl?
Asked Answered
O

1

11

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?

Onym answered 9/4, 2010 at 16:19 Comment(2)
Good question. I think the difference is between HtmlControl & a WebControl. But would love to hear more background on this one...Gumma
@Gumma I can understand if one is HtmlControl and the other is WebControl, but there are differences between various WebControls.Onym
M
1

I think it was designed ok, I don't think it was an oversight; those are the controls where text is the primary focus of the purpose of the control. I do see your point because that would be very convenient to have controls utilize more of these types of interfaces.

Monomer answered 9/4, 2010 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.