Ben Santiardo
asked on
How To Clone an ASP Menu Control's MenuItems
I created a class that manages the creation of all MenuItems to a Menu Object. Once my class finishes, it returns a single MenuItem reference (which I call ROOT), under which all other MenuItems are attached. I store this object reference using a Session Variable so that I can access it through my Web Application. In the header portion of my MasterPage, I placed code that takes the Session Menu Reference, and looks at each of the ROOT's ChildItems, and attaches them to it's Menu control. I was hoping that this way, I have one prebuilt master menu tree structure, that all pages can just use when they load. Here is my problem...When I .Add() the ChildItem from ROOT to the current pages Menu Object, it physically changes the parent reference on the ChildMenuItem to the ne Menu object, thereby literally ripping it off ROOT. I tried creating a method where I passed ROOT ByVal in the hopes it would create a copy rather then use a reference, no luck. I looked for a Clone() method on the MenuItems object, no such luck there either.
Somehow I need to create a clone of ROOT, so that when I rip off each ChildItem, I don't actually disturb the original MenuTemplate ROOT in memory, so that when the use navigates to a new page, the new page can access the original ROOT menu object and rebuild the menu again.
Any ideas?
So far, the only option I can see (which I am not fond of) is creating my own Clone() method in my class which manually creates a copy of the entire tree structure of the ROOT object...
Somehow I need to create a clone of ROOT, so that when I rip off each ChildItem, I don't actually disturb the original MenuTemplate ROOT in memory, so that when the use navigates to a new page, the new page can access the original ROOT menu object and rebuild the menu again.
Any ideas?
So far, the only option I can see (which I am not fond of) is creating my own Clone() method in my class which manually creates a copy of the entire tree structure of the ROOT object...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER