|
Rank: Newbie Groups: Member
Joined: 6/11/2012 Posts: 4
|
I am looking at this example and I would like to adapt something like this to not only get data from a table, but to also dynamically load it on the page. This way, only the active parts of the menu would get loaded. Is this possible, and are there examples of this being done? Thanks, Andrew
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, You can dynamically build your menu whatever you want: http://demo.essentialobjects.com/Demos/Menu/Programming/Server%20Side%20Programming/Dynamically%20Modifying%20Menu/Demo.aspxLoading it from a table is just one of the "shortcut" to load many items at once. I do not know what you meant by "only the active parts of the menu would get loaded" though. In ASP.NET, the whole page is reloaded every time your page is requested/posted back, so there is no such thing as "only the active parts of the menu would get loaded". It's always a full reload on the server side. The difference is how this reload occurs: whether it's a full reload from your database; or a reload from view state based on post back data, or a combination of both, etc. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 6/11/2012 Posts: 4
|
I'm talking about client-side. If there are 2 menu items that each have say 50 children elements, I don't want the client to have to download both subtrees if they are only going to look at one of them. I want them to only download the parts of the menu that they are viewing. Does that make any more sense? I want a postback to be triggered on a mouseover/click of an element that potentially has children elements.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You can do that with AJAX but I am not sure if it's worth it. Here I will give you the details as to how to load 50 children items for a single root item. It will be something like this:
1. Initially you would have a "root" menu with only one root item (you can have as many root item as you want, just repeat the logic described below). This root item has a single child item. This child item is a dummy "place holder" child item;
2. The dummy "place holder" child item is associated to a "CustomItem" control. CustomItem is a featured provided by our menu that allows you to put anything inside a menu item. You can think "CustomItem" as a standard ASP.NET Panel control that can holds anything else;
3. The CustomItem contains a CallbackPanel. The CallbackPanel then contains a "child menu". This menu has 50 items. This child menu's Visible is initially set to false;
4. When user clicks the root menu item, you make an AJAX call through the CallbackPanel and updates the child menu's visible to true;
Note this method has the following implications: 1. There is a time delay between the time user clicks the menu item and the time all child items are loaded. This usually will confuse users as they expect a menu to instantly opens it sub menu; 2. This will reduce the initial page load time but will not save you on band width as it introduces a second post back;
Overall I would suggest you against this solution because a menu supposes to be instant. If you have to dynamically load child items, consider using a TreeView together with the populate on demand feature.
Hope this helps.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 6/11/2012 Posts: 4
|
Thanks. I think that should work. I am aware that there will be a bit of a delay, but for my purposes, that is acceptable.
|
|
Rank: Newbie Groups: Member
Joined: 6/11/2012 Posts: 4
|
Okay, I'm trying to work through this a bit and I have another question.
If I programatically add a MenuItem and set RaisesServerEvent = true, how do I create a handler for it server-side?
Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You never need to create a handler for the MenuItem. Server side event is handled on the Menu, not on the MenuItem. So you would always handle the item click event at a single place no matter how many menu items you have.
Thanks!
|
|