简体   繁体   English

如何从抽象的 UserControl 继承?

[英]How do I inherit from an abstract UserControl?

If I have a class如果我有 class

abstract class DetailsForm : UserControl

then然后

AppDetailsForm : DetailsForm
BoxDetailsForm : DetailsForm

I can take advantage of inheritance to stick logic in DetailsForm.cs that applies to elements common among the tags in AppDetailsForm.aspx and BoxDetailsForm.aspx .我可以利用 inheritance 将逻辑粘贴到DetailsForm.cs中,该逻辑适用于AppDetailsForm.aspxBoxDetailsForm.aspx中的标签中常见的元素。 These tags appear in both, in exactly the same place.这些标签出现在两者中,在完全相同的位置。 There is duplicated header and footer code in AppDetailsForm.aspx and BoxDetailsForm.aspx that I'd rather stick in DetailsForm.cs . AppDetailsForm.aspxBoxDetailsForm.aspx中有重复的 header 和页脚代码,我宁愿坚持在DetailsForm.cs中。

The problem is I would need to stick a reference in DetailsForm.aspx that would refer to the content of the.aspx file in a child derived directly from that class.问题是我需要在DetailsForm.aspx中添加一个引用,该引用将引用直接从该 class 派生的子项中的 .aspx 文件的内容。

However, currently, it only shows the content of AppDetailsForm.aspx or BoxDetailsForm.aspx , and ignores anything in DetailsForm.cs , so it seems like the reference to the other file should go AppDetailsForm.aspxDetailsForm.cs and BoxDetailsForm.aspxDetailsForm.cs .但是,目前它只显示AppDetailsForm.aspxBoxDetailsForm.aspx的内容,并忽略DetailsForm.cs中的任何内容,因此似乎对其他文件的引用应该 go AppDetailsForm.aspxDetailsForm.csBoxDetailsForm.aspxDetailsForm.cs

I don't know how to do this, and I suspect I'm approaching this the wrong way.我不知道该怎么做,而且我怀疑我以错误的方式处理这个问题。

I think Master pages are built for what you are trying to do.我认为母版页是为您正在尝试做的事情而构建的。

Take a look at this link .看看这个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM