|
-
Apr 27th, 2006, 03:41 PM
#1
Thread Starter
Hyperactive Member
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
-
Apr 27th, 2006, 04:07 PM
#2
Frenzied Member
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.
-
Apr 27th, 2006, 04:19 PM
#3
Thread Starter
Hyperactive Member
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.
-
Apr 28th, 2006, 03:37 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|