<Items>
<asp:MenuIt开发者_高级运维em 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.
//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;
}
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 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.
精彩评论