简体   繁体   中英

user control inherits from custom control

I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user control from this custom control?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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