Replacing a user control with another one

Discussion in 'ASP .Net' started by John, Jul 7, 2003.

  1. John

    John Guest

    Hi all,

    How do I completely remove a dynamically-loaded user control and replace it
    with another one?

    Regards
    John.
     
    John, Jul 7, 2003
    #1
    1. Advertising

  2. John

    David Waz... Guest

    To remove the old control:

    parentControl.Controls.Remove(o_OldControl) ' remove ONE control
    from parent
    OR
    ParentControl.Controls.Clear ' Remove ALL
    controls from parent

    Then, to add the new control:
    parentControl.Controls.add(o_NewControl) ' add to parent as the
    Next sibling
    OR
    parentControl.Controls.AddAt(iIndexPosition, o_NewControl) ' add to
    parent at a specific location


    You could also not put ANY control in your HTML template, and just add the
    correct control within the code-behind at run-time.


    "John" <> wrote in message
    news:#...
    > Hi all,
    >
    > How do I completely remove a dynamically-loaded user control and replace

    it
    > with another one?
    >
    > Regards
    > John.
    >
    >
     
    David Waz..., Jul 7, 2003
    #2
    1. Advertising

  3. Hi John,

    Just remove it from the control tree and add the new one, take a look at the
    ControlCollection type

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    and not by private mail.

    "John" <> wrote in message
    news:%...
    > Hi all,
    >
    > How do I completely remove a dynamically-loaded user control and replace

    it
    > with another one?
    >
    > Regards
    > John.
    >
    >
     
    Victor Garcia Aprea [MVP], Jul 7, 2003
    #3
    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. qwerty
    Replies:
    3
    Views:
    9,300
    Scott Allen
    Sep 30, 2004
  2. et
    Replies:
    1
    Views:
    534
    Yunus Emre ALPĂ–ZEN [MCSD.NET]
    Jun 29, 2005
  3. =?Utf-8?B?REo=?=
    Replies:
    2
    Views:
    479
    =?Utf-8?B?REo=?=
    Dec 1, 2005
  4. et
    Replies:
    0
    Views:
    152
  5. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    294
    Chris Hohmann
    Apr 11, 2005
Loading...

Share This Page