Access element item on content page through nested master page

All I want to do is access the element <body>from the code for the content page and add the class name to it.

I have a top level main page with an element <body>. Then I have a nested main page, which is the main page for the content page. From the code behind the content page, I want to add the class name to the body element. It's all.

I have this with the top-level master:

<body id="bodyNode" runat="server">

I added this to the code 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 my aspx content page:

<% @ MasterType VirtualPath="~/MasterPage.master"%>

Then the message will change to:

bodyNode unavailable due to protection level

, , , 2 , -, : (

+5
2

, runat = "server" node, HTMLControls. .

public void Page_Load(Object sender, EventArgs e)
{ 
//Inject onload and unload
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("bodyNode");
body.Attributes.Add("class", "home-page");   
}


, -.

"body" , Master.FindControl() , .

, Master.Master.FindControl() -, , Master.Master ( , ), FindControl() .

+11

, body, . .

0

All Articles