The inside is a set of server for a body property, but it can be derived to some other HTMLControl

Source: Internet
Author: User
The snippet below uses the Attributes collection of the <body> tag (implemented as an HTMLControl object) To reference its standard HTML attributes. This method gives your programmatic access to any of the HTML attributes, normally hard-code into your <body> Tag.

The second method uses the Style object of the HTMLControl object. By making calls to the Style object "Add Method", you can add custom styles to your <body> tag. These are implemented as a inline style tag when it's rendered to the browser.
Because of this, your want to whether the style for you are going to implement are compatible with the browser are targeting.

The techniques used here can is used to set the properties of ' any HTML control ' does not have a Server control equival Ent. An example would is the <p> tag.


Sample code 1:use The "Attributes" collection of the body tag


<%@ Page language= "C #"%>

<script language= "C #" runat= "Server" >
protected void Page_Load (object sender, EventArgs e) {
Body. attributes["bgcolor"] = "#CCCCCC";
}
</script>

<body id= "Body" runat= "Server" >
This is the body text.
</body>



Sample Code 2:use The "Style" collection of the body tag


<%@ Page language= "C #"%>

<script language= "C #" runat= "Server" >
protected void Page_Load (object sender, EventArgs e) {
Body. Style.add ("Background-color", "#CCCCCC");
}
</script>

<body id= "Body" runat= "Server" >
This is the body text.
</body>



Notes:
Be sure to add the runat= "server" attribute to your body tag and give it ID




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.