本文介绍了不是所有的System.Web.UI.WebControl班,Text属性为什么要实施ITextControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,为什么只有某些 System.Web.UI.WebControl 控件实现某些接口时,他们有一个接​​口的相同的属性。

I'm curious why only some System.Web.UI.WebControl controls implement certain interfaces when they have the same properties of an interface.

例如,有很多具有Text属性,但仅控制下实施 ITextControl

For instance, there are plenty of controls that have a Text property but only the following implement ITextControl:


  • 标签

  • 文字

  • DataBoundLiteral

  • 文本框

  • 列表控件

(文本框和列表控件实际执行的IEditableTextControl它实现ITextControl)

(TextBox and ListControl actually implement IEditableTextControl which implements ITextControl)

TableCell的,按钮,超链接和别人不一样,所以我必须写code这样的

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;
}

而不是这种

control.Text = value;

这是一个设计决策或监督?

Was this a design decision or an oversight?

推荐答案

我觉得它的设计好了,我不认为这是一个监督;那些,其中文本的控制的目的的主要焦点的控制。我不明白你的意思,因为那将是非常方便的控制更多地利用这些类型的接口。

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.

这篇关于不是所有的System.Web.UI.WebControl班,Text属性为什么要实施ITextControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:03