Retrieve MenuItem with "special" text in Asp.Net - asp.net

I have a WebControls.Menu which holds several MenuItem.
I can use FindItem to retrieve most of them.
But it doesn't work for the two items which text is more than just a word.
Those two items' text being:
Save as...
Add new member
I tried setting the separator to | (pipe character) just to be sure it wasn't just that but it didn't fix my problem.
Is there something wrong when using a space or a dot?

Since FindItem of the Menu-Control uses the Value of an MenuItem to find it and not the Text, set and use that Property to find specific controls.
This also makes the FindItem-Function language-indipendent.
ASPX
<asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="3">
<Items>
<asp:MenuItem Text="Datei" Value="File">
<asp:MenuItem Text="Neu" Value="New"></asp:MenuItem>
<asp:MenuItem Text="Öffnen" Value="Open"></asp:MenuItem>
</asp:MenuItem>
</Items>
</asp:Menu>
C#
Menu1.FindItem("File");

Related

Add text to ASP.NET MenuItem web control Text attribute with an existing Resource file reference in it

I have this line of code in a web page
<asp:MenuItem Text="<%$ Resources:AppGlobal , Uitloggen %>"/>
Which outputs "Log in" in the menu item when rendered
I want to add a prefix, "foo: Log in", for example
Is this possible? My failed guesses are variations of
<asp:MenuItem Text="'foo:' + <%$ Resources:AppGlobal , Uitloggen %>"/>
Caveat: the addition must be made in the markup not the codebase
Thanks,
Jim

ASP:MENU On click open submenu

I have the following ASP:Menu
<asp:Menu id="menu_mymenu" runat="server" OnMenuItemClick="menu_mymenu_Click">
<Items>
<asp:MenuItem Text="menu_1" Value ="menu_1">
<asp:MenuItem Text="menu_a" Value="menu_a" />
<asp:MenuItem Text="menu_b" Value="menu_b"/>
</asp:MenuItem>
</Items>
</asp:Menu>
On mouse over it displays submenus menu_a and menu_b. I would like the onclick on menu_1 to display the submenus menu_a and menu_b in the same way without posting back. Is there anyway to do this?
It looks like this is not something that is particularly easy to do and may be a bit hacky. I've seen a lot of suggestions of trying to use a treeview instead of the menu control. Anyway here are some resources I found and a solution that appears may do the trick:
http://forums.asp.net/t/1250342.aspx
Is it possible to force a menu popout to trigger on click instead of mouseover?
If it is absolutely necessary to have this be on click then it would be worth looking into a solution that fits your needs. In this case I would recommend looking into a treeview or looking at a purely css / javascript solution.
Hopefully this gets you down the right path!
I have customized as per the requirement; below is the link for complete solution.
https://stackoverflow.com/a/60986351/3099784

Turn off link on menu items without URLs

I am building a menu for my asp.net application using the Menu control which is in turn being fed by a table via a Hierarchical data object. It works great, except that I cannot figure out how to configure the Menu control to disallow clicking on the menu items with no designated URLs.
For instance, I have a static toplevel menu item. I hover my mouse over it and a dynamic menu list appears for my choosing pleasure. Each dynamic menu item contains a link to a page that is invoked when I click my mouse on it. Whereas the static top level menu goes nowhere. How can I make it so that clicking on that top level static menu does not act like it is a link?
Thanks
jw
Is this perhaps what you are looking for?:
<Items>
<asp:MenuItem Selectable="false" Text="Search Engines" >
<asp:MenuItem NavigateUrl="http://www.google.com" Text="Google"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.google.com" Text="Google"></asp:MenuItem>
<asp:MenuItem NavigateUrl="http://www.google.com" Text="Google"></asp:MenuItem>
</asp:MenuItem>
</Items>
Good luck!

In Chrome menu suddenly messes up and says Expand

I have an asp.net menu with a few menuitems. 1 of the items has submenuitems.
Problem is that after clicking around on my site for a while, the menu's formatting will suddenly get messed up (the background image will only show in a tight rectangle around the text, and the text will be lower than the separator images) and the text of the menuitem with submenuitems has the phrase Expand MenuItem_Text added to it ("Setup" -> "Setup Expand Setup"), but it's not actually expandable.
I've discovered that logging out and then logging back in solves this, as does clearing the cache, however, I can't expect my users to know that.
I already have the AppleWebKit line in my code, so it's not that.
Edit:
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" BackColor="transparent"
StaticMenuItemStyle-ItemSpacing="0" StaticEnableDefaultPopOutImage="False" DynamicEnableDefaultPopOutImage="false">
<Items>
<asp:MenuItem NavigateUrl="~/Main.aspx" Text="Home" SeparatorImageUrl="~/Images/menubarmid.png" />
<asp:MenuItem Text="Setup" SeparatorImageUrl="~/Images/menubarmid.png" Selectable="false">
<asp:MenuItem NavigateUrl="~/ASetup.aspx" Text="A" />
<asp:MenuItem NavigateUrl="~/BSetup.aspx" Text="B" />
</asp:MenuItem>
<asp:MenuItem NavigateUrl="~/Logout.aspx" Text=" Logout "></asp:MenuItem>
</Items>
<StaticHoverStyle CssClass="static_hover_style" />
<DynamicHoverStyle CssClass="dynamic_hover_Style" />
<StaticMenuStyle CssClass="static_menu_style" />
<DynamicMenuStyle CssClass="dynamic_menu_style" />
<StaticMenuItemStyle CssClass="static_menuitem_style" />
<DynamicMenuItemStyle VerticalPadding="3px" HorizontalPadding="10px" CssClass="dynamic_menuitem_style" />
</asp:Menu>
I came up with the same sort of issue and I found that setting the StaticPopOutImageTextFormatString property to an empty string made the equivalent of " expand Setup" to disappear .
It looks like Chrome was trying to display the alternate text for the pop-out image instead of simply not displaying an image to indicate that the link could pop out.
As such my asp code looked something like this:
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False" StaticPopOutImageTextFormatString="">
</asp:Menu>
This, in addition to the AppleWebKit code seems to allow my code to work. I did have to do a shift F5 in order to reset the cache every time I restart the test server.
I had this happen to an asp.net site of mine when it was deployed to a server. I eventually found that in IIS the target framework for the site was 2.0. I changed it to 4.0 and hey presto the sitemap menu worked as expected.

Clicking on menu item in Chrome does nothing

Evening all,
I am struggling with a couple of problems that I could do with your help with. I apologise if these have been covered in other pages, if they have could you point me in the direction of those pages. The problems are as follows:
I've got a simple website that contains a master page with a menu on it. The menu works fine with IE and Firefox but when I try it in Chrome clicking the menu doesn't seem to work.
Here is how I have set the menu up:
How do I get the click on the menu to display the correct page?
<asp:Menu ID="Menu1" runat="server" Height="16px" Orientation="Horizontal"
style="margin-top: 0px" Width="917px">
<Items>
<asp:MenuItem ImageUrl="~/Images/MenuHome.jpg" NavigateUrl="~/Default.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuMenu.jpg" NavigateUrl="~/Menu.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuPriceList.jpg" NavigateUrl="~/PriceList.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuOrdering2.jpg"
NavigateUrl="~/Ordering.aspx" >
</asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuOccasions.jpg"
NavigateUrl="~/Occasions.aspx">
</asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuWeddings2.jpg" NavigateUrl="~/Weddings.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuEvents.jpg" NavigateUrl="~/Events.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuGallery.jpg" NavigateUrl="~/Gallery.aspx"
></asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuContactUs.jpg"
NavigateUrl="~/ContactUs.aspx" >
</asp:MenuItem>
<asp:MenuItem ImageUrl="~/Images/MenuBlog.jpg"
NavigateUrl="~/dasblog/default.aspx" >
</asp:MenuItem>
</Items>
</asp:Menu>
The menu is wrapping round on to two rows, how do I keep it on a single row?
Thanks for the help.
After some more digging I have found the solution.
The answer can be found here: http://forums.asp.net/p/1369765/2860698.aspx#2860698
I've copied the bits you will need and pasted it in here:
You need to add an App_Browsers folder to the project and add a new item Add New Item...
Select "Browser File" and name it Chrome.browsers.
Comment out the default stuff and insert this from the link above:
<browsers>
<browser refID="safari1plus">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.Menu" adapterType="" />
</controlAdapters>
</browser>
</browsers>
This will make the menu work, and it also stops it from wrapping around.

Resources