Solved

ASP.NET Menu Items

Posted on 2014-01-07
3
682 Views
Last Modified: 2014-01-09
Hi

I have an interesting issue.  I am using ASP.NET 4.0 navigation menu and I hide tabs based on a users level.  All seems to work well besides that all of the tabs seems to appear all by themselves after awhile.  The following is my my code to hide the tabs.

public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginView cp = (LoginView)FindControl("HeadLoginView");
            Label lbl = (Label)FindControl("Label1");
            if (cp.Page.User.Identity.IsAuthenticated == true)
            {
               // string lvl = "";
                if (Session["Level"] != null)
                {
                    lbl.Text = Session["Level"].ToString();
                    if (lbl.Text == "2")
                    {
                        NavigationMenu.Items.RemoveAt(0);
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));

                    }
                    else if (lbl.Text == "1")
                    {
                        NavigationMenu.Items.RemoveAt(0);
                    }
                    else
                    {
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("HR"));
                    }
                }
                             
            }
            else
            {
                NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));
                NavigationMenu.Items.Remove(NavigationMenu.FindItem("HR"));              

            }          
        }
    }
0
Comment
Question by:thomasm1948
  • 2
3 Comments
 

Author Comment

by:thomasm1948
Comment Utility
it seems to be appearing if the page is refreshed
0
 

Author Comment

by:thomasm1948
Comment Utility
Hi just modified my code.  I think this should work but still not sure

public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoginView cp = (LoginView)FindControl("HeadLoginView");
            Label lbl = (Label)FindControl("Label1");
            if (cp.Page.User.Identity.IsAuthenticated == true)
            {
               // string lvl = "";
                if (Session["Level"] != null)
                {
                    lbl.Text = Session["Level"].ToString();
                    if (lbl.Text == "2")
                    {
                        NavigationMenu.Items.RemoveAt(0);
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));

                    }
                    else if (lbl.Text == "1")
                    {
                        NavigationMenu.Items.RemoveAt(0);
                    }
                    else
                    {
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));
                        NavigationMenu.Items.Remove(NavigationMenu.FindItem("HR"));
                    }
                }
                else
                {
                    NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));
                    NavigationMenu.Items.Remove(NavigationMenu.FindItem("HR"));  
                }
                             
            }
            else
            {
                NavigationMenu.Items.Remove(NavigationMenu.FindItem("Admin"));
                NavigationMenu.Items.Remove(NavigationMenu.FindItem("HR"));              

            }          
        }
    }
0
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 500 total points
Comment Utility
Do this on the first time that the page do a postback

If not IsPostback then
 '--Your menu code here
 '--
End If

The other possible cause is that a user belongs to 2 groups and the gets remove for the first condition but reinstate by the second one
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now