Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Switching UserControl at runtime
Message
De
28/01/2011 10:29:51
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01497625
Message ID:
01497652
Vues:
42
>Hi all, I need to be able to dynamically switch between UserControls on a TabPage but am unsure as to how to elegantly achieve this. So far I've tried creating another uc , adding it to the TabPage's control collection and calling the new uc's BringToFront() method. This works but how do I reinstate the original uc ? also I assume the new uc is still in the control collection of the TabPage so how do I reuse it if an when I need to ? or should I remove it ? Hope this makes sense to someone out there - maybe my thought process is screwed ?

A couple of thoughts:

1) What you're doing currently is ok. Since you haven't removed the original UserControl, it is still in the TabPage's Controls collection, so you could just use BringToFront() on the original UserControl when you need it. The downside to this is that probably more memory is consumed, having them both loaded.

2) An alternative is to remove the original UserControl from the Controls collection before or after you add the second UserControl (after's probably better) and do the switching back-and-forth that way. The downside to this is that the UserControl may take awhile to instantiate and reload. This may appear slower to the user.

3) I think that if there's the possibility that you're going to be switching back-and-forth between those two UserControls more than once, then you might as well leave them both and use option #1. Otherwise, if you're just loading one, then loading the second and that's it, then go with option #2. If you've got more than just two UserControls that you'll be swapping, then definitely go with option #2.

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform