开发者

user control inherits from custom control

开发者 https://www.devze.com 2023-01-13 03:19 出处:网络
I have an custom contr开发者_运维技巧ol that extend System.Web.UI.UserControl. Is it possible to inherit user control from this custom control?So long as you have not marked the control as sealed, you

I have an custom contr开发者_运维技巧ol that extend System.Web.UI.UserControl. Is it possible to inherit user control from this custom control?


So long as you have not marked the control as sealed, you can inhrit from it and create other user controls that use the functionality already written.

So long as UserControl is part of the inheritance chain, everything should work as you would expect.


Yes. Simply swap out your custom UserControl class in your user control's code-behind. All that is necessary is that the base user control derive from System.Web.UI.UserControl as you describe.

public partial class MyUserControl : MyBaseUserControl
{
    // ...
}

If you are not using a code-behind, you can use the Inherits attribute in the <%@ Control %> directive to specify the base class.


Yes, in fact is very useful as you can have common methods available for all of your controls through this inherited custom control. It is that standard practice in our shop that no control inherits directly from System.Web.UI.UserControl but from the extended control in our common library.

0

精彩评论

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