Body Tags Change from codebehind page

  • Thread starter Thread starter RJDev
  • Start date Start date
R

RJDev

Hello,
Is teher anyone who can tell me how to change the body properties from a
code behind paghe.
Regards
RJ
 
Yes there's a way...

set your body tag to have a runat=server attribute see below

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

Then declare the body tag element as a HtmlGenericControl as below
protected System.Web.UI.HtmlControls.HtmlGenericControl bodyTag;

Then you can add attributes to the body tag by using the syntax

bodyTag.Attributes.Add("bgcolor","#CCCCCC"); // This will set the body
bgcolor to be grey

That should do what you need.

Matt
http://www.3internet.com
Inigo Content Management System - c#, asp.net, xml cms
 
Hey,

This is a bit tricky because body tag isn't a server control.

Turn body into server control
- From HTML, add runat="server" and id="myBody"
- In code
public class WebForm1 : System.Web.UI.Page { protected
System.Web.UI.HtmlControls.HtmlGenericControl myBody;
 
Thnx, That works fine.
Can you also use this for the header tag to insert META TAGS from a
database? Otherwise i just do it an onther way.
Regards,
RJ
 
I had the same question about BODY attributes and you answered it
nicely. One unfortunate thing I noticed though is that when the IDE
views the page in Design View, it removes the Page_Load initialization.
Is there a way to correct this?

Thanks.

Tim
 
I had the same question about BODY attributes and you answered it
nicely. One unfortunate thing I noticed though is that when the IDE
views the page in Design View, it removes the Page_Load initialization.
Is there a way to correct this?

Thanks.

Tim
 
Back
Top