Link to home
Start Free TrialLog in
Avatar of hussainAbid
hussainAbid

asked on

ASP.NET Nested User Control

Hi Experts,

I have one page and two user controls. User Control B is a nested control within Control A and Control A is sitting at Page.

I am adding one instance of Control B to Parent control A it displays fine but then I have a command button on Control A (parent control) and every time command button is clicked one instance of Control B is added to a container in Control A. But problem is only very first added instane of Control B is being displayed/rendered. Nothing else is showing. how can I achieve this.

I am trying to achieve an effect like some email web interfaces allow additions of as many "TO" addresses as possible and new rows keep appearing. Let  say that row was a user control and I want to appear one new when "Add" is clicked.

Please help i have spent two days but cudnt make it work !!!
Avatar of Bondo
Bondo

here is an example of how I've dynamically loaded multiple versions of he same control on another control.  My case it was a questionnaire system.
For Each oUQ As UserQuestion In UserQuestions
                        If IsNothing(oUQ.Response) = False Then
                            If Left(oUQ.QuestionSeq, Len(Criteria)) = Criteria Then

                                Dim oLoad As QuestionControl = DirectCast(LoadControl("ERGOQuestion.ascx"), QuestionControl)

                                oLoad.UserQuestion = oUQ
                                oLoad.BindData()
                                pnlQuestions.Controls.Add(oLoad)
                            End If
                        End If
                    Next oUQ

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vikram Singh Saini
Vikram Singh Saini
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hussainAbid

ASKER

Thanks very much for answer but here are two issues:
1) even though i have marked the control code behind a SERianlizable it still gives error that useControl is not marked as serializable.
2) controls added dynamically does not appear (only very first added one does) and seems like it is because creating a control instance at a command button level is far too late for the page life cycle to render it along. Any suggessions please?

Looking forward to hear from fellas out there :)
Hello hussainAbid,

Did you tried suggestion as I asked you?

Regards,
VSS
Many thanks and sorry for late response i was put on another rather urgent task :). Happy programming!!