简体   繁体   English

使用分部类扩展WebControl

[英]Extending a WebControl using a partial class

Is is possible to extend, for instance, the HyperLink control using a partial class? 例如,可以使用部分类来扩展HyperLink控件吗?

I'd like to define some custom properties on the control, without having to extend the class... like so... 我想在控件上定义一些自定义属性,而不必扩展类......就像这样......

<asp:HyperLink runat="server" CustomPropertyA="a" CustomPropertyB="b" />

And be able to use them on OnInit/OnPreload etc. 并且能够在OnInit / OnPreload等上使用它们。

No. Partial types only allow you to specify the code for a type within multiple source files within the same project. 不可以。部分类型允许您在同一项目中的多个源文件中指定类型的代码。 That's all. 就这样。 They're a compile-time change only - they don't affect the object model, or what you can do with types which already exist etc. 它们只是一个编译时更改 - 它们不会影响对象模型,也不会影响已经存在的类型等。

It sounds like you may just want to create a new class derived from HyperLink instead. 听起来您可能只想创建一个派生HyperLink的新类。

As Jon said, you have to create a new class derived from HyperLink. 正如Jon所说,你必须创建一个派生自HyperLink的新类。 But if you are after to keep the old tag structure, use tag mapping as well. 但是,如果您要保留旧标记结构,请使用标记映射

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

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