?
Solved

ASP.NET Menu Items

Posted on 2014-01-07
3
Medium Priority
?
698 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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