I need to make some of the NavigationMenu items visible only to some users.
In my case I need to make 2 of them available only to admin.
I searched google and I found a command which works :
NavigationMenu.Items.Remove(NavigationMenu.FindItem(“HERE GOES THE NAME OF THE MENU I NEED TO REMOVE”));
Till here,everything is ok.
But which command do I need to use to make it available again ?
Please help me. Thnx in advance 😉
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
if (Matrix.UserLoggedId == Guid.Empty)
{
hlLogin.Visible = true;
lblUsername.Visible = false;
lnkLogout.Visible = false;
}
else
{
// here goes the code to add the menu
hlLogin.Visible = false;
lblUsername.Visible = true;
lnkLogout.Visible = true;
Marin.Employee.DetailsDataTable emp = Matrix.GetEmployeeByUniqueId(Matrix.UserLoggedId);
if (emp.Rows.Count > 0)
{
lblUsername.Text = emp.Rows[0]["Firstname"].ToString();
bool isAdmin =Convert.ToBoolean(emp.Rows[0]["isAdmin"]);
if (isAdmin)
{
//here goes the code to show the menu
}
else
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
}
}
}
}
Try this, replace x with correct values.
For more info on MenuItem check this –
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.aspx