Programmatically Adding Web User Controls

J

Jason Dunbar

Hi folks,

I have a scenario where I need to create multiple unique instances of
a Web User Control and add these controls as children to a PlaceHolder
Server Control. Here is my code so far:

private void newJourneyLeg()
{
// generate the index number based on the
current number of Dictionary Entries
int legIndex = arrLegControls.Count + 1;

// - trip leg controls must be created 'on the
fly' and so each one must take on a unique name
arrLegControls.Add(legIndex,
LoadControl("JourneyLeg.ascx"));


journeyLegs.Controls.Add((JourneyLeg)arrLegControls[legIndex]);
Trace.Warn("Leg Index Number",
legIndex.ToString());

}

Where 'arrLegControls' has been instantiated as a Hashtable.
'journeyLegs' is the ID/name of my PlaceHolder Server Control.

This method is called as part of an event handler. The event handler
is fired when a radio button is clicked (though this will eventually
be triggered by a 'new' button to create a new journeyLeg).

The Event Handler has been tied to three Radio Buttons.

When a Radio button is first clicked, the control is created fine.
When another of the radio buttons is clicked, no other controls are
created and added.

When the same Radio Button is clicked twice, the control appears the
first time, then disappears with the second click.

Any help on this would be greatly appreciated.

Thank you.

Kind Regards,

Jason
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top