|
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.
|
|
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!
|
|
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.
|
|
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!
|
|
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.
|
|
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
|
|
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.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
|
|