locked
Inheriting from custom user control RRS feed

  • Question

  • User-257878023 posted

    Hello,

    I have an abstract custom user control (.ascx) that displays the ASP.NET tree view control with some additional buttons.

    The concrete implementations are server controls that inherit from this control and provide the specific functionality (providing data etc.). But when I use these controls in a page, the child controls of the base control (e.g. the tree view) cannot be referenced - a null reference exception is thrown.

    How can I achieve this? Why are these controls not initialized?

    Thanks for any hint! 

    Monday, July 21, 2008 9:55 AM

Answers

  • User-294030300 posted

    Hey,

    When using a User Control base class, it cannot have a visual front-end;only the code-behind portion is reused.  So the base class can have code that is common across the concrete implementations, but it would have to render the UI through code and not through the ASCX file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2008 10:19 AM
  • User481221548 posted

    Hi Brain

    I agree if we speak from the out-of-the-box ASP.NET.
    But you can add such a kind of Functionality, like:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2008 1:28 PM

All replies

  • User-294030300 posted

    Hey,

    When using a User Control base class, it cannot have a visual front-end;only the code-behind portion is reused.  So the base class can have code that is common across the concrete implementations, but it would have to render the UI through code and not through the ASCX file.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2008 10:19 AM
  • User481221548 posted

    Hi Brain

    I agree if we speak from the out-of-the-box ASP.NET.
    But you can add such a kind of Functionality, like:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 21, 2008 1:28 PM