Question

I have a dynamically generated menu (C#), like this:

MenuItem(string text, string value, string imageUrl, string navigateUrl, string target)

MenuItem AdminLevel1 = new MenuItem("Admin", "Admin"); MenuItem AdminPedidosRegisto = new MenuItem("Questions", "AdminQ"); NavigationMenu.Items.Add(new MenuItem("Messages Received", "AdminMessagesR", "", "./Admin/Messages.ascx", "ContainerIframe")); AdminPedidosRegisto.ChildItems.Add(new MenuItem("Pending", "AdminPending", "", "./Admin/Pedidos.ascx", "ContainerIframe"));

Where 'ContainerIframe' is the iFrame's ID and 'NavigationMenu' is the (asp:Menu)'s ID.

I want to disable the click action in the parent items that don't have an URL set, so the page doesn't refresh when someone clicks it.

Is there a way?

Was it helpful?

Solution 2

Thanks to @Manibhadra (this is enough for parent items and child items)

window.onload = function ()
{
    var menuTable = document.getElementById("<%=NavigationMenu.ClientID%>");
    var menuLinks = menuTable.getElementsByTagName("a");
    for (i = 0; i < menuLinks.length; i++)
    {
        menuLinks[i].onclick = function () {  }
    }
}

OTHER TIPS

menuitem.NavigateUrl = "javascript:;";

if (MenuItem.NavigateUrl == "")
{
 MenuItem.Selectable = false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top