Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

  • Thread starter Denny Smolinski via .NET 247
  • Start date
D

Denny Smolinski via .NET 247

I have been searching forever. Here is my problem.

I have form of 3 panels of information for car insuranceinformation.

1st panel is general information but I need to retrieve theNUMBER OF FAMILY members to see how many names I need for mynext panel that is dynamically generated based upon my drop downlist selection. I can generate panel 2 with the number of namesI need but the problem is then posting the data from thetextboxes to the next page.

ERROR: Object reference not set to an instance of an object.

I try to retrieve from a dynamic box txt1, txt2, etc. I havetried creating the boxes on the fly and even in the page_initsection and just set visible = false. Please if anyone couldhelp. Thank you
 
E

Eidolon

One mistake that drove me batty at first with dynamic controls and
apparently is a very common mistake from what i saw online is this...

In order to get anything out of your previous control, you MUST add it back
into the control heirarchy at EXACTLY the same place (this is where the
placeholders come in handy) as it was before, otherwise the framework will
not be able to repopulate it all. Here is the way i do this. This has worked
flawlessly and beautifully for me.
In my page i put the following:

I add a Literal control named "ltlLastControl", and set the Text property to
the path for my first/default ascx file.
I add a PlaceHolder control named "bucket".

In my Page_Load I add the following code as the first line:
<code>
If Me.LastControl <> "" Then SwapControl(Me.LastControl)
</code>

Then i also add the following code to my page:
<code>
Protected ReadOnly Property LastControl() As String
Get
Return ltlLastControl.Text
End Get
End Property

'// NewControl receives the ASCX path to load
Protected Sub SwapControl(ByVal NewControl As String)
Dim ctl As Web.UI.Control = LoadControl(NewControl)

bucket.Controls.Clear()
bucket.Controls.Add(ctl)

ltlLastControl.Text = NewControl
End Sub
</code>
 

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,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top