Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To add an external css file from the code behind

Tags:

html

c#

css

asp.net

I've a CSS file, say SomeStyle.css. Is it possible for me to apply this style sheet document to an aspx page from its code behind?

like image 409
Niranjan Avatar asked Sep 20 '11 16:09

Niranjan


People also ask

What is external CSS code?

External CSS is a file that contains only CSS code and is saved with a ". css" file extension. This CSS file is then referenced in your HTML using the <link> instead of <style>.

What way to insert CSS is using another file?

Note: There are two different ways to import a CSS file into another using @import url(“style2. css”); or @import “style2. css”; or directly import any CSS file or multiple CSS file in the HTML file directly within <style>@import “style1.

Which extension is used in HTML for external CSS file?

In External css we use . css extension. . css extension is used for saving a css file.


1 Answers

You can add literal controls to your header control:

Page.Header.Controls.Add(
    new System.Web.UI.LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/SomeStyle.css") + "\" />"));
like image 158
Matthew Abbott Avatar answered Sep 25 '22 07:09

Matthew Abbott