hide menu item

Posted on 2010-11-19
Last Modified: 2012-05-10
I'm trying to hide an menu item and i can do it but when i click a logout button it causes and error.

I have one option that does it perfect but throws an error when I click the log out button.

The other option shows the child item and disables its child items. I don't want the child item visible at all.


<asp:Menu ID="Menu1" runat="server" BackColor="#E3EAEB" 

    DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" 

    ForeColor="#666666" Orientation="Horizontal" StaticSubMenuIndent="10px">

    <StaticSelectedStyle BackColor="#1C5E55" />

    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

    <DynamicHoverStyle BackColor="#666666" ForeColor="White" />

    <DynamicMenuStyle BackColor="#E3EAEB" CssClass="adjustedZIndex" />

    <DynamicSelectedStyle BackColor="#1C5E55" />

    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

    <StaticHoverStyle BackColor="#666666" ForeColor="White" />


        <asp:MenuItem Text="Account" Value="Account">

            <asp:MenuItem NavigateUrl="~/profile.aspx" Text="Profile" Value="Profile"></asp:MenuItem>

            <asp:MenuItem NavigateUrl="~/password.aspx" Text="Change Password" Value="Change Password"></asp:MenuItem>

            <asp:MenuItem Text="Manage Accts" Value="ManageAccts">

                <asp:MenuItem Text="Select Acct" Value="SelectAcct" NavigateUrl="~/accounts.aspx"></asp:MenuItem>

                <asp:MenuItem Text="Acct Status" Value="AcctStatus" NavigateUrl="~/accountstatus.aspx"></asp:MenuItem>





<asp:LoginStatus ID="LoginStatus1" runat="server" 

onloggingout="LoginStatus2_LoggingOut" Font-Size="Smaller" Visible="true" />

protected void Page_Load(object sender, EventArgs e) //, MenuEventArgs ee


        System.Web.Profile.ProfileBase p = HttpContext.Current.Profile;

        MembershipUser currentMember = Membership.GetUser(p.UserName.ToString());

        if (Request.IsAuthenticated)


            if (Roles.IsUserInRole(currentMember.UserName, "Customer"))



                Menu1.Items[0].ChildItems.RemoveAt(2); //hide the Account/Manage Accts menu item

                ////disable childmenu items

                //foreach (MenuItem item in Menu1.Items)


                //    foreach (MenuItem childItem in item.ChildItems)

                //    {

                //        if (childItem.Text == "Manage Accts") childItem.Enabled = false; //*** want to hide this option

                //    }


//other stuff here as well


protected void LoginStatus2_LoggingOut(object sender, LoginCancelEventArgs e)


        System.Web.Profile.ProfileBase p = HttpContext.Current.Profile;

        MembershipUser currentMember = Membership.GetUser(p.UserName.ToString());

        if (Roles.IsUserInRole(currentMember.UserName, "Customer"))


            Profile.SelectedCustomerId = "";

            Profile.SelectedCompany = "";



        //destroy session



        //destroy page history - stop user from clicking back button and reposting same data



    protected void DestroyPageHistory()


        //destroy page history - stop user from clicking back button and reposting same data

        Response.Expires = 0;

        Response.ExpiresAbsolute = DateTime.Now;

        Response.CacheControl = "no-cache";


Open in new window

Question by:vicomin
  • 3
  • 2

Expert Comment

ID: 34177364
there is not visible property on a menuitem, you will have to remove the item from the menu and add later if needed

Author Comment

ID: 34179708
how do i got about doing that? if i use the following it works:


however, when i click the logout button it throws an error - out of index which it should but I dont need that portion of the code to execute.

Expert Comment

ID: 34188745

for me to help you further I need to see the code for both the front and the back

Accepted Solution

vicomin earned 0 total points
ID: 34193511
i got it working by using a session variable and using a linkbutton for the logout process.

Author Closing Comment

ID: 34324571
i figure it out

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

17 Experts available now in Live!

Get 1:1 Help Now