Solved

ASP.NET Menu Items

Posted on 2014-01-07
3
691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

762 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