Welcome Guest Search | Active Topics | Sign In | Register

Problem with MenuItem.SubMenu.Items.Remove(MenuItem) Method Options
Massis
Posted: Monday, December 10, 2007 12:15:05 PM
Rank: Newbie
Groups: Member

Joined: 12/5/2007
Posts: 9
I'd apprecaite your help with the follwoing.

I'm using the MenuItem.SubMenu.Items.Remove(MenuItem) method to delete a menu item from the items collection. When the page refreshes, the deleted menu item (MenuItem.Text) does not appear in the menu. However, when I access the menu item through the follwoing code, the "deleted" menu item node is still there.

Code: C#
EO.Web.MenuItem oMenuItem = 
   (EO.Web.MenuItem) mnuTemplate.FindItem(strMenuItemPath);
EO.Web.MenuItem oParent = oMenuItem.ParentItem;
oParent.SubMenu.Items.Remove(oMenuItem);


Can you please point out what I'm doing wrong?

Thanks,
Massis


eo_support
Posted: Monday, December 10, 2007 12:58:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi Massis,

I am not sure what you mean by "when I access the menu item through the following code", isn't the code you pasted the same as "I am using the MenuItem.SubMenu.items.Remove"?

Unless you have explicitly saved the result to somewhere else, it's perfectly normal that the menu is reset after you re-get the page. Re-getting the page (as oppose to posting back the same page) discard everything you have done and refetch the page brand new from the server again.

Thanks
Massis
Posted: Monday, December 10, 2007 1:58:12 PM
Rank: Newbie
Groups: Member

Joined: 12/5/2007
Posts: 9
I'll try to clarify.

I'm developing my own menu builder screen which enables the user to add and delete menu items and submenus. The user starts with an empty menu and adds one menu item and/or submenu to the menu control at a time. The menu is never re-initialized during page load. In fact, there are no problems as long as the user is adding menu items and submenus to the menu control. The problem I've described only occurs when I delete a menu item.

Here's how the delete process works.

1. The user selects the menu item to delete by clicking on the menu item.

2. In the ItemClick event handler, I save the XPath (MenuItem.Path) of the node the user clcked on in a session variable. And, I assign the MenuItem.Text to a text box on the screen. I also enable a "Delete Menu Item" button.

3. The page reloads and the MenuItem.Text of the selected item appears in the textbox, and the "Delete Menu Item" button is enalbed.

4. The user clicks on the "Delete Menu Item" button.

5. The Click event handler for the "Delete Menu Item" button fires. I use the saved XPath (see step 2) to obtain a reference to the selected menu item (via the EO.Web.Menu.FindItem method). I then delete the menu item using the MenuItem.ParentItem.SubMenu.Items.Remove method.

When the page reloads afte step 5, the deleted menu item no longer appears (which is correct) and the remaining menu items are shifted to the left by one position. However, When the user selects the same position in the menu again (see steps 1 & 2 above) the MenuItem.Text of the deleteed item appears in the text box instead of the MenuItem.Text of what appears appears on the page.

I hope this clarifies the problem that I'm seeing.

Massis
eo_support
Posted: Monday, December 10, 2007 6:17:25 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi Massis,

Is it possible for you to separate the problem into a test page and then either paste the code here or email the code to us? It would be much easier if we can reproduce the problem at here. I'll PM you as to where to send.

Thanks
eo_support
Posted: Tuesday, December 11, 2007 5:19:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi Massis,

We have received and looked into the code you provided. It appears to be a bug, however we are able to find a workaround for you while you awaits the fix.

To workaround the problem, explicitly set the menu item's ItemID whenever you create a new menu item. For example, if the current code is:

Code: C#
EO.Web.MenuItem item = new EO.Web.MenuItem("- Add Item-");


You can change it to:

Code: C#
EO.Web.MenuItem item = new EO.Web.MenuItem("- Add Item-");
item.ItemID = Guid.NewGuid().ToString();


Of course, you are free to set ItemID to any other value, just to make sure that different child items of the same parent item have different values. Note you need to set ItemID for every dynamically created.

Once you set the ItemID, deleting and server event should start to work.

Thanks
Massis
Posted: Tuesday, December 11, 2007 10:59:10 AM
Rank: Newbie
Groups: Member

Joined: 12/5/2007
Posts: 9
Thanks for the workaround. It resolved the issue.

Massis


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.