开发者

Extending a WebControl using a partial class

开发者 https://www.devze.com 2023-04-12 23:37 出处:网络
Is is possible to extend, for instance, the HyperLink control using a partial class? I\'d like to define some custom properties on the control, without having to extend the class... like so...

Is is possible to extend, for instance, the HyperLink control using a partial class?

I'd like to define some custom properties on the control, without having to extend the class... like so...

<asp:HyperLink runat="server"开发者_JAVA百科 CustomPropertyA="a" CustomPropertyB="b" />

And be able to use them on OnInit/OnPreload etc.


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.


As Jon said, you have to create a new class derived from HyperLink. But if you are after to keep the old tag structure, use tag mapping as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消