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.