How to program add BODY Attributes

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
 
G

Guest

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);
 
C

chenhong

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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top