Web UserControl inheritance

I

Ivan A. Vasilyev

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
 
T

Teemu Keiski

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

Ivan A. Vasilyev

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

Teemu Keiski

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top