What causes dynamic changes?
You can do this in server side code quite easily.
On the .aspx page you can:
<asp:Panel id="menuRow" runat="server"> </asp:Panel>
I use Panel here because it gives us a nice container for controls and displays a <div> around them.
Then in your code behind, you will have something like:
// Determine correct user control to load string pathToUserControl = DetermineTopMenu(); // Load the user control - calling LoadControl forces the correct lifcycle events // to fire, and ensures the control is created properly. var topMenu = LoadControl(pathToUserControl); // Add the control to the menuRow panels control collection. menuRow.Controls.Add(topMenu);
I suggested that you have a way to determine which user control you want to display, and that you named it in such a way as to generate the path to the user control quite difficult. I hid this logic in a call to the DetermineTopMenu method, because:
- I do not know what logic you are using.
- This simplifies testing, expansion, etc.
For more information about LoadControl, see the documentation .
source share