1

I have an asp:Menu which currently has 4 menuitems within it. I have been able to set the id for the menu as a whole but the hyperlinks for the menuitems are mostly the same. I would like to be able to identify each one using an Id or similar. Is this possible?

This is my menu:

<asp:Menu ID="NavigationMenu" runat="server" Orientation="Horizontal" 
          OnMenuItemClick="NavigationMenu_OnMenuItemClick"
          CssClass="Menu">
          <StaticMenuItemStyle ForeColor="Black" CssClass="MenuItem" ItemSpacing="20" />
          <StaticSelectedStyle CssClass="MenuItemSelected"></StaticSelectedStyle>
          <Items>
              <asp:MenuItem Value="0" Text="New" Selected="True"></asp:MenuItem>
              <asp:MenuItem Value="1" Text="Approved"></asp:MenuItem>
              <asp:MenuItem Value="2" Text="Rejected"></asp:MenuItem>
              <asp:MenuItem Value="3" Text="Done"></asp:MenuItem>
          </Items>
</asp:Menu>

And this is the result in the browser for the second and third menuitems (not currently selected)

<a class="NavigationMenu_1 MenuItem NavigationMenu_3" href="javascript:__doPostBack('NavigationMenu','2')" style="border-style:none;font-size:1em;">Rejected</a>


<a class="NavigationMenu_1 MenuItem NavigationMenu_3" href="javascript:__doPostBack('NavigationMenu','3')" style="border-style:none;font-size:1em;">Done</a>

As you can see they are very similar. Any solution to this?

Thomas
  • 27
  • 1
  • 6

1 Answers1

0

we cannot able assign id for a menuitem

You can get the "menu object" with javascript by the following pattern.

var myMenu = document.getElementById("MyMenu");

If you inspect the rendered HTML you will see that it is rendered as a table (with id MyMenu) and one element for every item.

So you can hide/show any of your elements like this:

document.getElementById("MyMenu").tBodies[0].rows[0].style.display = "none";

Here's a nice tutorial on table DOM elements:

http://www.howtocreate.co.uk/tutorials/javascript/domtables

table

caption
    childNodes[] 
tHead
    rows[]
        cells[]
            childNodes[]
tFoot
    rows[]
        cells[]
            childNodes[]
tBodies[]
    rows[]
        cells[]
            childNodes[]
rams
  • 1
  • 1