这是我想达到的目的。
为CustomControlA
,我有
public void OverrideableMethod()
{
// some codes here
}
,我有UserControlB
。 我想从CustomControlA
上覆盖UserControlB
的方法。 这可能吗?如果是,如何?
我能想出的最好的东西是在UserControlB
上创建一个同名的方法,并从那里调用CustomControlA.OverrideableMethod()
。
更新: 谢谢你的答案,我很欣赏他们。
的代码是这样的:
public class CustomControlA : CustomControl
{
public virtual void OverrideableMethod()
{
// do something
}
}
public class UserContorlB : System.Web.UI.UserControl
{
protected CustomControlA someVariableForCustomControlA;
// here lies the problem, on how to override CustomControlA.OverrideableMethod() here
// without inheriting CustomControlA itself
}
这里绿水青山问题。尽可能多,我想远离继承CustomControlA,因为允许UserControlB
继承一个基类。 这是可能的,以覆盖CustomControlA.OverrideableMethod()
给出上面的情况?
你为什么这样做? –
并且你不能用这种方式覆盖CustomControlA,但是你可以添加一个Event到CustomControlA,然后从USerControlB注册到它 –
@TMcKeown我希望让UserControlB继承另一个基类。 – AceMark