How (if at all) can you make an ASP.NET UserControl inherit from another UserControl?

前端 未结 3 1296
不思量自难忘°
不思量自难忘° 2021-01-11 13:41

In Windows Forms it\'s easy to inherit one user control from another. The inherited control contains all the controls of the parent form, and you can add some more. Can the

相关标签:
3条回答
  • 2021-01-11 13:54

    You could certainly inherit the base user control in code and insert your additional controls in code, if you are talking building in a visual designer then I'm not sure. I'm aware of creating composite controls from both system.web controls and user controls so there's no reason that your new control couldn't contain another user control with additional controls added around it.

    0 讨论(0)
  • The difference between the windows forms example and the web forms example, is the control has a tagged portion. I imagine this can be overcome, some day, as web applications compile everything (at least in some instances), but it is not the case today.

    You can, however, slap a user control on another user control, ad nauseum. It will not give you inheritance, but it does allow you to adorn a particular control with additional controls by making a composite of the original control and the stuff you need to add to it. That might solve your problem?

    0 讨论(0)
  • 2021-01-11 14:17

    The short answer is no it can't be easily done. There's no inheritance between user controls or webforms. You can create an inheritance hierarchy between the code behinds classes but the gui components aren't inherited.

    0 讨论(0)
提交回复
热议问题