Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 02, 2012 08:41 AM by Dave Sussman
Member
631 Points
629 Posts
Mar 01, 2012 10:20 AM|LINK
When I use this code to access a Master Page Menu Item, it works well but it fails when I try to run from a class.
Menu masterMenu = Master.FindControl("NavigationMenu") as Menu;
It gives error: Object Reference not set to an instance of an object.
41 Points
25 Posts
Mar 01, 2012 01:49 PM|LINK
Hi-
Maybe try
Menu MasterMenu = (Menu)Page.Master.FindControl("NavigationMenu")
-Nici
Contributor
2346 Points
478 Posts
Mar 02, 2012 05:25 AM|LINK
Hi,
Can you share the class that you are using?
Thanks,
Bimal
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Mar 02, 2012 08:41 AM|LINK
The class doesn't have a property called Master, so that's the object that is null. You can't directly access the page or master from within a class.
What is it you're trying to do in that class? There will be ways to do what you want, but we need to know what you are trying to do.
rpk2006
Member
631 Points
629 Posts
Why accessing master page menu item from class gives error?
Mar 01, 2012 10:20 AM|LINK
When I use this code to access a Master Page Menu Item, it works well but it fails when I try to run from a class.
Menu masterMenu = Master.FindControl("NavigationMenu") as Menu;It gives error: Object Reference not set to an instance of an object.
Trouble88
Member
41 Points
25 Posts
Re: Why accessing master page menu item from class gives error?
Mar 01, 2012 01:49 PM|LINK
Hi-
Maybe try
Menu MasterMenu = (Menu)Page.Master.FindControl("NavigationMenu")Bimalvv
Contributor
2346 Points
478 Posts
Re: Why accessing master page menu item from class gives error?
Mar 02, 2012 05:25 AM|LINK
Hi,
Can you share the class that you are using?
Thanks,
Bimal
Bimal
Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: Why accessing master page menu item from class gives error?
Mar 02, 2012 08:41 AM|LINK
The class doesn't have a property called Master, so that's the object that is null. You can't directly access the page or master from within a class.
What is it you're trying to do in that class? There will be ways to do what you want, but we need to know what you are trying to do.