0
<Items>
    <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
    <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>

I have this menu How can I disable it during page load

page load
If (Userrole==Something)
{
hide menu item 2
}

How can I do that.

The Evil Greebo
  • 7,013
  • 3
  • 28
  • 55
John
  • 467
  • 7
  • 17
  • 27
  • there's some code samples here: http://stackoverflow.com/questions/4939031/can-i-hide-show-aspmenu-items-based-on-role – Doozer Blake Oct 07 '11 at 12:33

3 Answers3

1

The most feasible solution will be security trimming. Simple and understandable. Read all about it here

Mark as answer if you found it useful. I benefited from it. Let me know if you have any doubts.

Naman
  • 51
  • 8
1

Add the runat and id tags to your menu items

<Items>
    <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" id="mnuDefault" runat="server"/>
    <asp:MenuItem NavigateUrl="~/About.aspx" Text="About" id="mnuAbout" runat="server"/>
</Items>

then in your codebehind you can program against them and set enabled = false

page load
If (Userrole==Something)
{
    mnuAbout.Enabled = false;
}
The Evil Greebo
  • 7,013
  • 3
  • 28
  • 55
1
 //Going through first level items
 if (e.item.NavigateUrl == "")
    e.item.Enabled = false;

 //Going through submenu item
foreach (MenuItem item in e.Item.Items)
{
     if (item.NavigateUrl == "")
         item.Enabled = false;
}
Alon Adler
  • 3,984
  • 4
  • 32
  • 44