ASP. NET dynamically adds CSS style JS title keywords to the front end, cssjs
Many website readers can change their favorite styles. Some websites want to share backend code with multiple sites and only change the front-end styles. They can dynamically replace CSS styles and JS styles. For webform development, you can use the following methods:
The process is to first read data from the data or xml, and then assign the value to the front-end page
HTML <meta> label Addition
HtmlMeta mtdes = new HtmlMeta (); // create an instance
Mtdes. Name = "Description"; // tag
Mtdes. Content = this. Descriptionp; // Content
Header. Controls. Add (mtdes); Add css attributes
HTML <Link> label addition, which is the key to dynamically adding CSS styles
HtmlLink hlk = new HtmlLink (); // create an instance
Hlk. Href = "css/a.css"; // Add a css address
Hlk. Attributes. Add ("rel", "stylesheet"); // Add css Attributes
Hlk. Attributes. Add ("type", "text/css"); // Add css Attributes
Header. Controls. Add (hlk); // Add it to the page Header Control
The following is the same:
HtmlLink csslink2 = new HtmlLink ();
Csslink2.Href = "css/css1.css ";
Csslink2.Attributes. Add ("rel", "stylesheet ");
Csslink2.Attributes. Add ("type", "text/css ");
Header. Controls. Add (csslink2 );
Add JS dynamically
HtmlGenericControl jslink = new HtmlGenericControl ("script"); Create a script instance
Jslink. Attributes ["type"] = "text/javascript"; // indicates the js text category.
Jslink. Attributes ["src"] = "js/elf. js"; // URL of JS
Header. Controls. Add (jslink); // Add it to the page Header Control
Add title and description
This. Titlep = dr ["title"]. ToString ();
This. Descriptionp = dr ["breif"]. ToString ();
This. Label3.Text = dr ["title"]. ToString ();
This. Label4.Text = dr ["About"]. ToString ();
Page. Title = Titlep; Add Title method 2
In fact, there are many methods. You can expand your ideas and implement them in other ways.
If any of the above articles is correct