Solved

ASP.NET Menu Items

Posted on 2014-01-07
3
689 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 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