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