Results 1 to 15 of 15

Thread: Hiding a Menu Item on a MasterPage?

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    Re: Hiding a Menu Item on a MasterPage?

    No difference, it still asks for a New...This has to be easier than we are making it

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Hiding a Menu Item on a MasterPage?

    When you "New" an object, you are creating another instance of it. You don't want to create another menu, you just want a pointer that points back to the original on the Master Page. Hmmm.....looking at it in the editor, it looks like the MenuItem object doesn't have a Visible property. Try just setting the text to an empty string "" and see what happens.


    Try this and see what happens:

    DirectCast(Master.FindControl("ContentMenu"),Webcontrols.Menu).Items(1).Text = ""

    Comment out:

    'MasterMenu is the name of the Menu control
    Dim MyMasterMenu As Web.UI.Page = Master.FindControl("ContentMenu")

    ' And then you can access individual menu items
    MyMasterMenu.Items(1).Visible = False
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    261

    Re: Hiding a Menu Item on a MasterPage?

    No luck, it looks like its not finding the MasterPage or the control on the master page. The error is "Object Reference not set to an instance of the object"

    I agree with your logic, I just can't figure out how to touch the control to make the change.

  4. #4
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Hiding a Menu Item on a MasterPage?

    seidel1,

    I'm still writing my first asp.net 2.0 app and so don't know if this is the best way to do it but here's what i do and it works.... (Sorry it's in C# but should be easy enough to convert).

    Make a property on the master page...
    Code:
        public int HideItem
        {
            set
            {
                //Remove menu item at specified position
                this.MainMenu.Items.RemoveAt(Value);
            }
        }
    Then at top of .aspx page...
    Code:
    <%@ MasterType VirtualPath="~/base.master" %>
    this allows you to access the master page from your derived page.

    Then in code-behind for your aspx page...
    Code:
            //Remove the item at position 1
            this.Master.HideItem = 1;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width