Dynamically Loading User Controls

Discussion in 'ASP .Net Web Controls' started by B. Suitt, Apr 16, 2008.

  1. B. Suitt

    B. Suitt Guest

    In ASP.Net 1.1 dynamically loading user controls was very simple, however
    with the 2.0+ framework I apparently can not use the same code to accomplish
    the same thing and I have not found any examples of how to make it work.

    My example code is as follows:

    Dim MyControl As Web.UI.Control

    MyControl = LoadControl("testcontrol.ascx")
    PlaceHolder1.Controls.Clear()
    MyControl.ID = "CurrentControl"
    PlaceHolder1.Controls.Add(MyControl)

    The control will display properly on the screen using the above code,
    however if I click on a button that resides inside of the user control, no
    event is fired and the control itself just disappears. For the project that
    I am working on, it's not an option to load potentially 50 user controls and
    just hide and display them. I really need to be able to load them
    dynamically.

    I'm sure lots of people have encountered this problem by now and no doubt
    have the solution. Thanks in advance!
     
    B. Suitt, Apr 16, 2008
    #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. Ben Miller [msft]
    Replies:
    0
    Views:
    615
    Ben Miller [msft]
    Aug 5, 2003
  2. sonic_soul
    Replies:
    0
    Views:
    527
    sonic_soul
    Aug 14, 2003
  3. Nick Stansbury

    loading user controls dynamically

    Nick Stansbury, Jul 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    352
    John Saunders
    Jul 19, 2004
  4. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    517
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
  5. Bob Rock
    Replies:
    1
    Views:
    689
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
Loading...

Share This Page