Nested UserControl Problem

G

Giovanni

I have been stumped by this problem for the past 2 days:

Assuming I have a GridView contained within a UserControl. The grid
contains 3 columns (Column 1: QuestionNumber, Column 2: QuestionText, and
Column 3: TemplateField). In the third column (the TemplateField), I have a
dragged-and-dropped a UserControl (QuestionTypeUserControl). The
QuestionTypeUserControl has an Integer property: QuestionTypeID, and itself
is empty (contains no controls). On the GridView's RowDataBound event, I
pass a DataKey value to QuestionTypeUserControl.QuestionTypeID. This is
where the problem is:

I have built several other UserControls which resemble server controls,
but have additional functionality (Ex.: DropDownListExUserControl,
TextBoxExUserControl have an additional label, etc...). Depending on the
value of QuestionTypeID, the QuestionType UserControl (thusfar empty), would
decide which child UserControl(s) to add to itself. In essence, the Parent
(QuestionTypeUserControl), determines which children it will add to itself,
based on a value (QuestionTypeID).

1. What is the best approach to accomplish this. Must I use the
..LoadControl in the parent (QuestionTypeUserControl)? and which event is best
to do this?

2. What considerations must I take to compensate for ASP.NET 2.0's
dynamic compilation model, both in the parent and child UserControls.

I guess in the end, it is a 3 layer-nested UserControl (GridView
contains a UserControl type TemplateField, which itself contains any number
of UserControls).

Thank you for all your help and ideas.

Regards,

Giovanni P.
 
Y

yoga weazel

Q1. If I follow you correctly I would recommend using LoadControl in the
PreRender event.

Q2. The only thing I can think of off hand is registering the child controls
in the parent. This won't be a problem if you have a pre-defined list of
child control types.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top