Replacing a user control with another one

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi all,

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

Regards
John.
 
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.
 
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.
 
Back
Top