Summary of methods for adding HTML elements dynamically in ASP. NET and asp.net

Source: Internet
Author: User

Summary of methods for adding HTML elements dynamically in ASP. NET and asp.net

This article describes how to add HTML elements dynamically in ASP. NET. We will share this with you for your reference. The details are as follows:

When you use asp.net for web development, the information in

1. Add a style sheet dynamically

/* Dynamically Add a style sheet */HtmlLink link = new HtmlLink (); link. attributes. add ("type", "text/css"); link. attributes. add ("rel", "stylesheet"); link. attributes. add ("href", "/css/base.css"); this. header. controls. add (link );

2. dynamically add styles

/* Dynamically Add a Style */style Style = new style (); Style. font. size = 20; style. foreColor = System. drawing. color. navy; style. backColor = System. drawing. color. lightGray; this. header. styleSheet. createStyleRule (style, null, "body ");

3. dynamically add Meta

/* Dynamically add Meta */HtmlMeta meta = new HtmlMeta (); meta. name = "keywords"; meta. content = "Your keywords here"; this. header. controls. add (meta); meta = new HtmlMeta (); meta. name = "company"; meta. content = "microsoft"; this. header. controls. add (meta); meta = new HtmlMeta (); meta. name = "date"; meta. content = DateTime. now. toString ("yyyy-MM-dd"); meta. scheme = "YYYY-MM-DD"; this. header. controls. add (meta );

4. dynamically add js files

/* Dynamically Add a js file */HtmlGenericControl si = new HtmlGenericControl (); si. tagName = "script"; si. attributes. add ("language", "javascript"); si. attributes. add ("type", "text/javascript"); si. attributes. add ("src", "/js/common/base. js "); // note the path written in this. page. header. controls. add (si );

Notes

The

Related Article

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.