asp.net| Dynamic | style sheet
Because at some point in order to save the cost of the stylesheet download, we will divide the CSS into different files, and call with only the available
In. NET WEB programming based on template pages, you sometimes encounter the problem of how to dynamically add CSS style sheet files to the head tag.
I've thought about some ways in the past.
For example, write some if else statements directly in the head to determine the current access page
But this is definitely not the best choice.
Next I'll introduce another better way to add
Write the following code in the Page_Init of the page
Protected Sub Page_Init (ByVal sender as Object, ByVal e as System.EventArgs) Handles Me.init
Dim Myhtmllink as New htmllink ()
Myhtmllink.href = "~/css/msg.css"
MYHTMLLINK.ATTRIBUTES.ADD ("rel", "stylesheet")
MYHTMLLINK.ATTRIBUTES.ADD ("type", "Text/css")
PAGE.HEADER.CONTROLS.ADD (Myhtmllink)
End Sub to solve this problem.
The same can be added meta
Dim hm1 as New Htmlmeta ()
Dim HM2 as New Htmlmeta ()
Dim Head as HtmlHead = Page.header
Hm1. Name = "keywords"
Hm1. Content = "Words that describe your Web page"
Head. Controls.Add (HM1)
HM2. Name = "Date"
HM2. Content = DateTime.Now.ToString ("Yyyy-mm-dd")
HM2. Scheme = "Yyyy-mm-dd"
Head. Controls.Add (HM2)