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!
Related
So I have an asp.net MenuItem user control created ( similar to what this post has ) within inside a MVC view. The user control works as expected, except the NavigateUrl.
This is the menuitem inside the usercontrol.
<asp:MenuItem Text="View Account" NavigateUrl="~/pages/account.aspx" />
The link looks fine if the user control is being rendered from a webform, it shows
http://localhost/SampleTest/pages/account.aspx
However, put the usercontrol inside the mvc view will have it rendered as
http://localhost/SampleTest/SampleTest/pages/account.aspx
There's an extra domain name "SampleTest" in the url.
What should I do to get rid of the extra domain name?
you need to update your URL navigation to URL.content.
<asp:MenuItem Text="View Account" NavigateUrl="#URL.content("~/pages/account.aspx")" />
code is not tested, but you can do like these.
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");
My ASP.Net Menu & associated MenuItems are not rendering correctly in Chrome. That is to say, they are all rendering simultaneously, in sequential order down the page, rather than as drop-down menus.
They work normally when I run the page from the solution (including in Chrome), but when I deploy it to the test server, the nested nature of the menus are lost. In my example, "Admin Maintenance," "Grid Maintenance," "Today Screen" and "Setup should all be items under the "Admin" menu, and the last 3 should be items under "Setup." They are setup correctly and, as mentioned before, they work fine when run from within VS.
A screenshot:
My code:
<asp:Menu ID="Menu1" runat="server" CssClass="menu"
EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal" StaticDisplayLevels="1">
<Items>
<asp:MenuItem Text="PTS Home" Value="PTS Main" NavigateUrl="Default.aspx">
</asp:MenuItem>
<asp:MenuItem Text="Admin" Value="Admin">
<asp:MenuItem Text="Admin Maintenance" Value="Admin_Admin Maintenance" NavigateUrl="~/Secure/Admin/AdminMaintenance.aspx">
</asp:MenuItem>
<asp:MenuItem Text="Grid Maintenance" Value="Admin_Grid Maintenance" NavigateUrl="~/Secure/Admin/GridMaintenance.aspx">
</asp:MenuItem>
<asp:MenuItem Text="Today Screen" Value="Admin_Today Screen" NavigateUrl="~/Secure/Admin/TodayScreen.aspx">
</asp:MenuItem>
<asp:MenuItem Text="Setup" Value="Admin_Setup">
<asp:MenuItem Text="Reserve Owner Codes" Value="Admin_Setup_Reserve Owner Codes"
NavigateUrl="~/Secure/Admin/MaintainOwnerCodes.aspx"></asp:MenuItem>
<asp:MenuItem Text="Reserve Product Codes" Value="Admin_Setup_Reserve Product Codes"
NavigateUrl="~/Secure/Admin/MaintainProductCodes.aspx"></asp:MenuItem>
<asp:MenuItem Text="Enter New Grade" Value="Admin_Setup_Enter New Grade" NavigateUrl="~/Secure/Admin/MaintainGrades.aspx">
</asp:MenuItem>
</asp:MenuItem>
</asp:MenuItem>
... //Other items
</Items>
</Menu>
The weirdest/most annoying thing is that on the production server, when I first load the page, it does this, but I leave & come back, it fixes itself. On the test server, it just stays broken.
Also, this behavior occurs in IE 8, as well, though I suspect that that's a red herring, and none of my users use IE 8, anyway.
I've included the IIS keyword, as I have a feeling that this is more a server issue than a code issue, but I'm not certain. I'm not certain which version of Windows Server/IIS we run, & our server admin is out at the moment. I'll update the question later when I have that info, but I was hoping that there might be an answer anyway.
UPDATE
Windows Server 2008 R2 SP1, IIS7.
Figured out what was going on. Came upon it somewhat by accident.
The page uses mixed content (the menu itself being unsecure content). Chrome automatically blocks unsecure content on mixed pages, displaying a shield in the address bar. Click the shield, tell it to load unsecure content, and bam - no more weird behavior.
http://knowledgebase.pearsonschool.com/kmp/article/AA-05523/0/GPOINT%3A-How-do-I-display-mixed-content-with-Google-Chrome.html
Of course, I should probably just fix the menu to be secure, but this at least tells me what was going on, and may help others with similar problems.
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
I had a asp.net Menu control on the master page and binded in the runtime based on the user access rights to the module. The problem I face is the MenuItemClick event is not fired when I view the website in the Internet Explorer(6.0). But the same is working fine in Firfox. I tried googling but none of the solutions worked for me. I was wondring if some one could help me to fix this.
There is no problem with Internet Explorer.
When you used MenuItem you probably used this form:
<asp:Menu ID="NavigationMenu" OnMenuItemClick="NavigationMenu_MenuItemClick" runat="server">
<items>
<asp:MenuItem Text="menuItem1" NavigateUrl="Web.aspx" />
<asp:MenuItem Text="menuItem2" NavigateUrl="otherWeb.aspx" />
</items>
</asp:Menu>
When you wrote in this form, the browser dosen't respect your event, because you gave it the URL to navigate to.
If you want that the browser will respect your event and handle it as well, you should delete the "NavigateUrl" attribute and it will work out.