views:

88

answers:

5

I want to display in a panel at run time different controls, depending on the menu selection.

Any ideas?

A: 

Put all of the possible controls in your panel, and then (assuming you're using the ASP.Net Menu control) set the appropriate control's .Visible property to True and all the other control's .Visible properties to False in the MenuItemClick event.

Joel Coehoorn
A: 

You only have to instantiate the controls you want and add it via

YourPanel.Controls.Add(yourcontrol)

I think that in VB must be almost the same.

Elph
Thanx.I found this totorial:http://quickstart.developerfusion.co.uk/QuickStart/aspnet/doc/ctrlref/userctrl/default.aspx
Haroldis
A: 

If you want all of your controls available always (for data sharing), you'll want to do as Joel suggested. Syntactically, however, I would say you could make it much easier if you associated the menu items to your controls inside the Page_OnLoad() like so:

Control1.Visible = MenuItem1.Selected;
Control2.Visible = MenuItem1.Selected || MenuItem2.Selected;
Control3.Visible = MenuItem3.Selected;

Hope that helps.

Lance May
A: 

1) Add all user controls inside a parent page with Visible = false. Depending menu selection, make Visible = true.

Advantages - Easy to implement

Disadvantages - Expensive. Every user control's Load event will be called on parent page is loaded.

2) Load a control dynamically to a place holder.

this.PlaceHolder1.Controls.Add(child);

Advantages - Light weight.

Disadvantages - Need to write some code if parent page wants to retrieve data from user control after post back.

winmyan