Forum Moderators: open

Message Too Old, No Replies

Manipulating the <BODY> tag from a content page

         

scubby

7:34 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



Is there a good way to add an ID= or a class= attribute to the body tag from a content page, when the body tag is sitting in a master page?

I'm looking for a good way to achieve per-page CSS, so that I can only apply certain rules to a specified page.

My dream would be able to do it in the page directive, like this:

<%@ Page Title="Whatever" ID="ContactPage" %>
<asp:Content...>

</asp:Content>

and then

<%@ Master %>

<body id="<%= Page.ID %>">
..
</body>

defanjos

5:28 pm on Nov 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



please disregard. I was thinking classic ASP, but your question is about .net

(edited)

seizer

11:29 am on Nov 18, 2007 (gmt 0)

10+ Year Member



Here's one way to do it:

In the master page, add an ID and a RUNAT to the body tag.

Then, in the codebehind of the content page, do something like this:

HtmlLiteral l = new HtmlLiteral();
l.Text = "<style>(your CSS goes here)</style>";
Page.Master.FindControl("IdOFYourBodyElement").Controls.Add(l);