How to program add BODY Attributes

  • Thread starter Thread starter jiatiejun
  • Start date Start date
J

jiatiejun

I want to add BODY Attributes

example:
from <body> to
<body leftmargin="0" topmargin="0"
or
from <body> to
<body onload="window_onload()"

how to set the BODY ?

thanks
 
add runat="server" attribute in your aspx.
You can add id="myBody" and then refer to it in the code as myBody,
or if you do not define an id, then you can find it by iterating through the
controls and comparing TagName, for example:
foreach (Control control in this.Controls){
if (control is HtmlGenericControl &&
((HtmlGenericControl)control).TagName=="body"){
// set your variable to this control
}
}
After you have located the body control, adding attributes is extremely
easy. There is a number of approaches. One of them is as follows:
myBody.Attributes.Add(attName, attValue);
 
<body runat="server" id="body1">

in c# you can treat the body like other server control.

body1.Attributes.add("name","value");
 
Back
Top