Access <body element from content page via a nested master page
- by danwellman
All I want to do is access the <body element from the code-behind of a content page and add a class name to it.
I have a top-level master page with the <body element in it. Then I have a nested master page which is the master page for the content page. From the code behind of the content page I want to add a class name to the body element. That's all.
I have this in the top-level master:
<body id="bodyNode" runat="server">
I added this to the code-behind for the content page:
Master.bodyNode.Attributes.add("class", "home-page");
And I get a message that:
System.Web.UI.MasterPage' does not contain a definition for 'bodyNode
If I add this to the aspx content page:
<% @ MasterType VirtualPath="~/MasterPage.master"%>
The message then changes to:
bodyNode is inaccessible due to its protection level
Please advise, I've wasted like 2 hours on what feels like something that should be really simple to do :(