The examples in this article describe how ASP. NET dynamically adds HTML elements. Share to everyone for your reference, as follows:
When using ASP. Web Development, the information in
1. Dynamically Add style sheet
/* Dynamically add style sheet */htmllink link = new htmllink (); link. Attributes.Add ("type", "text/css"); link. Attributes.Add ("rel", "stylesheet"); link. Attributes.Add ("href", "/css/base.css"); HEADER.CONTROLS.ADD (link);
2. Dynamic Add Style
/* Dynamically add 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, dynamic increase meta
/* Dynamically add meta*/htmlmeta meta = new Htmlmeta (); Meta. Name = "keywords"; meta. Content = "Your keywords here"; HEADER.CONTROLS.ADD (meta); meta = new Htmlmeta (); Meta. Name = "Company"; Meta. Content = "Microsoft"; HEADER.CONTROLS.ADD (meta); meta = new Htmlmeta (); Meta. Name = "date"; Meta. Content = DateTime.Now.ToString ("Yyyy-mm-dd"); Meta. Scheme = "YYYY-MM-DD"; HEADER.CONTROLS.ADD (meta);
4. Adding JS files dynamically
/* Dynamically add js file */htmlgenericcontrol si = new HtmlGenericControl (); Si. TagName = "Script"; Si. Attributes.Add ("Language", "JavaScript"), Si. Attributes.Add ("type", "Text/javascript"); Attributes.Add ("src", "/js/common/base.js");//Note the way the path is written this. Page.Header.Controls.Add (SI);
Precautions
Using the code above,
It is hoped that this article will help you with ASP.