Welcome Guest Search | Active Topics | Sign In | Register

Bug with MenuItem using CustomItem Options
mendy
Posted: Thursday, May 27, 2010 1:01:51 PM
Rank: Member
Groups: Member

Joined: 5/27/2010
Posts: 22
Hi,
I have tried a number of times to get customitem to work, and the width of the item has always been too small for the custom text.

I tried many things, until I finally realized that the width of the item was exactly as big as the biggest word in the text.

This led to the conclusion that the width of the customitem is being decided by the first word.
So the quick fix was for me to use   for spaces.

I hope this helps someone.
eo_support
Posted: Thursday, May 27, 2010 1:07:18 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Thanks for sharing. CustomItem is usually used in a fixed width context. In that case the sub menu would consider the whole CustomItem as a single block element and tries to automatically resize itself to accommodate the CustomItem. If you just want to display simple text, you can use raw HTML as menu item text.

Thanks!
mendy
Posted: Thursday, May 27, 2010 2:10:11 PM
Rank: Member
Groups: Member

Joined: 5/27/2010
Posts: 22
Hi,

Thanks for the tip.

The reason I was using a CustomItem is because I was trying to use Code Blocks (<%= %>)
within the MenuItem Text.

That is not allowed ( Code blocks are not supported in this context ).
So I was using a customItem instead, That's we're I noticed the problem.

eo_support
Posted: Thursday, May 27, 2010 2:22:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

I see what you are trying to do. In that case it will be better if you just use code behind to set menu item text. CustomItem is not really for that purpose. Also setting menu item text directly is more efficient in term of performance.

Thanks!
mendy
Posted: Thursday, May 27, 2010 3:01:42 PM
Rank: Member
Groups: Member

Joined: 5/27/2010
Posts: 22
Thanks for your responses.

So, using code behind, how do I invoke the ItemCreated method?

I was able to get the CustomItemCreated to invoke when creating the menu, but the ItemCreated does not seem to be invoked at all when hitting the page.
eo_support
Posted: Thursday, May 27, 2010 3:08:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Usually you don't use ItemCreated to set menu item text from code behind. You just get the item and set its property. For example, the following code would set the first top level item's text:

Code: C#
Menu1.Items[0].Text.Html = "Hi!";


This code set the second sub menu item of the third top item's text:

Code: C#
Menu1.Items[2].SubItems[1].Text.Html = "Hi!";


Thanks
mendy
Posted: Thursday, May 27, 2010 3:21:16 PM
Rank: Member
Groups: Member

Joined: 5/27/2010
Posts: 22
Thank you for replying.

Is there a way to use string to know which item?

For example Menu1.Items["Title"] ( ItemId or something similar )

Or do I always need to keep track of which element I'm up to.
eo_support
Posted: Thursday, May 27, 2010 4:21:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Yes. You can use FindItem function or SearchItems function. FindItem use "Path", while SearchItems can use item ID:

http://doc.essentialobjects.com/library/1/eo.web.basenavigator.finditem.aspx
http://doc.essentialobjects.com/library/1/eo.web.basenavigator.searchitems_overloads.aspx

Thanks


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.