Solved

ASP.NET Menu Items

Posted on 2014-01-07
3
686 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
ID: 39763325
it seems to be appearing if the page is refreshed
0
 

Author Comment

by:thomasm1948
ID: 39763378
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
ID: 39765616
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

18 Experts available now in Live!

Get 1:1 Help Now