Web UserControl inheritance

Discussion in 'ASP .Net Web Controls' started by Ivan A. Vasilyev, Jun 21, 2007.

  1. Hello.

    Could anyone please clarify one thing.

    Suppose I have to classes:
    1. A inherits UserControl
    2. B inherits A

    BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.

    Then suppose I want to instantiate control B. I have three options:
    1. Propgrammatically instatiate B through new B();
    2. Propgrammatically instatiate B through LoadControl("B.ascx");
    3. Declare control B in ASPX/ASCX of a container and refer B in code-behind
    file of a container.

    The quiestion is the following: Which of instantiation options are correct
    to use?

    I've tried (3) but it seems that html markup (in ASCX) of class A isn't
    being parsed, so those children of A (from ASCX) are not being created.

    TIA
    Ivan A. Vasilyev, Jun 21, 2007
    #1
    1. Advertising

  2. Ivan A. Vasilyev

    Teemu Keiski Guest

    Hi,

    ascx files aren't in the inheritance chain (assuming if I understand your
    scenario correctly). If you put B to derive from A, it means B derives from
    code-behind class of A, not the A.ascx being parsed through normal ASP.NET's
    mechanisms (it is parsed dynamically or via Page.ParseControl/LoadControl
    etc)

    I think master pages would be closer solution to this.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    "Ivan A. Vasilyev" <> wrote in message
    news:...
    > Hello.
    >
    > Could anyone please clarify one thing.
    >
    > Suppose I have to classes:
    > 1. A inherits UserControl
    > 2. B inherits A
    >
    > BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
    >
    > Then suppose I want to instantiate control B. I have three options:
    > 1. Propgrammatically instatiate B through new B();
    > 2. Propgrammatically instatiate B through LoadControl("B.ascx");
    > 3. Declare control B in ASPX/ASCX of a container and refer B in
    > code-behind file of a container.
    >
    > The quiestion is the following: Which of instantiation options are correct
    > to use?
    >
    > I've tried (3) but it seems that html markup (in ASCX) of class A isn't
    > being parsed, so those children of A (from ASCX) are not being created.
    >
    > TIA
    >
    Teemu Keiski, Jun 24, 2007
    #2
    1. Advertising

  3. Hello

    Thanx for the answer.
    I need to extend some ascx-based user control. So i think composition
    (insted of inheritance) is the only way to go.

    "Teemu Keiski" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
    ÓÌÅÄÕÀÝÅÅ: news:%...
    > Hi,
    >
    > ascx files aren't in the inheritance chain (assuming if I understand your
    > scenario correctly). If you put B to derive from A, it means B derives
    > from code-behind class of A, not the A.ascx being parsed through normal
    > ASP.NET's mechanisms (it is parsed dynamically or via
    > Page.ParseControl/LoadControl etc)
    >
    > I think master pages would be closer solution to this.
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    > "Ivan A. Vasilyev" <> wrote in message
    > news:...
    >> Hello.
    >>
    >> Could anyone please clarify one thing.
    >>
    >> Suppose I have to classes:
    >> 1. A inherits UserControl
    >> 2. B inherits A
    >>
    >> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
    >>
    >> Then suppose I want to instantiate control B. I have three options:
    >> 1. Propgrammatically instatiate B through new B();
    >> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
    >> 3. Declare control B in ASPX/ASCX of a container and refer B in
    >> code-behind file of a container.
    >>
    >> The quiestion is the following: Which of instantiation options are
    >> correct to use?
    >>
    >> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
    >> being parsed, so those children of A (from ASCX) are not being created.
    >>
    >> TIA
    >>

    >
    >
    Ivan A. Vasilyev, Jun 25, 2007
    #3
  4. Ivan A. Vasilyev

    Teemu Keiski Guest

    Sorry for delay, one way also is to put the layout/controls of the parent UC
    to be created in code. That way it is inherited.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    "Ivan A. Vasilyev" <> wrote in message
    news:...
    > Hello
    >
    > Thanx for the answer.
    > I need to extend some ascx-based user control. So i think composition
    > (insted of inheritance) is the only way to go.
    >
    > "Teemu Keiski" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
    > ÓÌÅÄÕÀÝÅÅ: news:%...
    >> Hi,
    >>
    >> ascx files aren't in the inheritance chain (assuming if I understand your
    >> scenario correctly). If you put B to derive from A, it means B derives
    >> from code-behind class of A, not the A.ascx being parsed through normal
    >> ASP.NET's mechanisms (it is parsed dynamically or via
    >> Page.ParseControl/LoadControl etc)
    >>
    >> I think master pages would be closer solution to this.
    >>
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >> "Ivan A. Vasilyev" <> wrote in message
    >> news:...
    >>> Hello.
    >>>
    >>> Could anyone please clarify one thing.
    >>>
    >>> Suppose I have to classes:
    >>> 1. A inherits UserControl
    >>> 2. B inherits A
    >>>
    >>> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
    >>>
    >>> Then suppose I want to instantiate control B. I have three options:
    >>> 1. Propgrammatically instatiate B through new B();
    >>> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
    >>> 3. Declare control B in ASPX/ASCX of a container and refer B in
    >>> code-behind file of a container.
    >>>
    >>> The quiestion is the following: Which of instantiation options are
    >>> correct to use?
    >>>
    >>> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
    >>> being parsed, so those children of A (from ASCX) are not being created.
    >>>
    >>> TIA
    >>>

    >>
    >>

    >
    >
    Teemu Keiski, Jun 29, 2007
    #4
  5. I have to avoid changing parent user control. But thanx anyway :) WBR.


    "Teemu Keiski" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
    ÓÌÅÄÕÀÝÅÅ: news:...
    > Sorry for delay, one way also is to put the layout/controls of the parent
    > UC to be created in code. That way it is inherited.
    >
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    > "Ivan A. Vasilyev" <> wrote in message
    > news:...
    >> Hello
    >>
    >> Thanx for the answer.
    >> I need to extend some ascx-based user control. So i think composition
    >> (insted of inheritance) is the only way to go.
    >>
    >> "Teemu Keiski" <> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
    >> ÓÌÅÄÕÀÝÅÅ: news:%...
    >>> Hi,
    >>>
    >>> ascx files aren't in the inheritance chain (assuming if I understand
    >>> your scenario correctly). If you put B to derive from A, it means B
    >>> derives from code-behind class of A, not the A.ascx being parsed through
    >>> normal ASP.NET's mechanisms (it is parsed dynamically or via
    >>> Page.ParseControl/LoadControl etc)
    >>>
    >>> I think master pages would be closer solution to this.
    >>>
    >>>
    >>> --
    >>> Teemu Keiski
    >>> AspInsider, ASP.NET MVP
    >>> http://blogs.aspadvice.com/joteke
    >>> http://teemukeiski.net
    >>>
    >>> "Ivan A. Vasilyev" <> wrote in message
    >>> news:...
    >>>> Hello.
    >>>>
    >>>> Could anyone please clarify one thing.
    >>>>
    >>>> Suppose I have to classes:
    >>>> 1. A inherits UserControl
    >>>> 2. B inherits A
    >>>>
    >>>> BOTH A AND B HAVE HTML MARKUP IN RELATED ASCX FILES.
    >>>>
    >>>> Then suppose I want to instantiate control B. I have three options:
    >>>> 1. Propgrammatically instatiate B through new B();
    >>>> 2. Propgrammatically instatiate B through LoadControl("B.ascx");
    >>>> 3. Declare control B in ASPX/ASCX of a container and refer B in
    >>>> code-behind file of a container.
    >>>>
    >>>> The quiestion is the following: Which of instantiation options are
    >>>> correct to use?
    >>>>
    >>>> I've tried (3) but it seems that html markup (in ASCX) of class A isn't
    >>>> being parsed, so those children of A (from ASCX) are not being created.
    >>>>
    >>>> TIA
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Ivan A. Vasilyev, Jul 2, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    662
    David Waz...
    Jul 3, 2003
  2. Ben Fidge

    Web UserControl and Visual Inheritance

    Ben Fidge, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    760
    Oleg Ogurok
    Jun 8, 2004
  3. Yuan
    Replies:
    1
    Views:
    3,117
    Scott Allen
    Jan 26, 2006
  4. Replies:
    0
    Views:
    461
  5. Kan Grewal

    Web Usercontrol in a Web Usercontrol not displaying...

    Kan Grewal, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    108
    Kan Grewal
    Jul 7, 2004
Loading...

Share This Page