Programmatically Adding Web User Controls

Discussion in 'ASP .Net Web Controls' started by Jason Dunbar, Nov 8, 2004.

  1. Jason Dunbar

    Jason Dunbar Guest

    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
    Jason Dunbar, Nov 8, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RCBTaGVsZG9u?=

    Adding validation controls programmatically

    =?Utf-8?B?RCBTaGVsZG9u?=, May 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,775
    =?Utf-8?B?RCBTaGVsZG9u?=
    May 11, 2004
  2. Tim Marsden

    Adding controls programmatically.

    Tim Marsden, May 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    572
    Steven Cheng[MSFT]
    May 25, 2004
  3. Guest
    Replies:
    4
    Views:
    7,160
    Steven Cheng[MSFT]
    Nov 9, 2005
  4. Chakravarti Mukesh

    Adding Controls Programmatically

    Chakravarti Mukesh, Jan 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,963
    brijesh patel
    Feb 14, 2013
  5. Adding Controls to a Web Forms Page Programmatically

    , Mar 17, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    162
Loading...

Share This Page