Search code examples
c#inheritanceweb-controls

Extending a WebControl using a partial class


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" CustomPropertyA="a" CustomPropertyB="b" />

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


Solution

  • 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.