Replacing a user control with another one

J

John

Hi all,

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

Regards
John.
 
D

David Waz...

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.
 
V

Victor Garcia Aprea [MVP]

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.
 

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
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top