Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a CSS file with HTMLTextWriter

Tags:

html

c#

css

asp.net

Using HTMLWriter I've been able to load individual pieces of CSS with the following:

protected static void FixHeaderStylesHeight(HtmlTextWriter writer)
{
    writer.RenderBeginTag(HtmlTextWriterTag.Style);
    writer.Write(".ms-siteicon-img { max-height: 80px; }");
    writer.RenderEndTag();
}

This is now getting more complicated and I'd like to load an external CSS file into the page, basically, if this was HTML I would use the following line:

<link rel="stylesheet" type="text/css" href="/stdtheme.css" />

How can I duplicate this kind of functionality using HtmlTextWriter?

like image 884
Michael A Avatar asked Jan 18 '26 00:01

Michael A


1 Answers

I don't have an IDE in front of me, but I believe I've done something like this in the past:

writer.AddAttribute(HtmlTextWriterAttribute.Href, "/stdtheme.css");
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
writer.RenderBeginTag(HtmlTextWriterTag.Link);
like image 108
Justin Van Bibber Avatar answered Jan 19 '26 14:01

Justin Van Bibber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!