The problem: I am embedding a CSS file into a custom control library with several controls. I want to share the same CSS file for all of the controls regardless of how many
I don't know why, but your solution didn't work for me, the ClientScript.IsClientScriptBlockRegistered call always returned false. But John Bledsoe's suggestion on the link you already provided (here) worked for me:
public static void IncludeStylesheet(Page page, string href, string styleID)
{
//Prevent the stylesheet being included more than once
styleID = "_" + styleID;
if (HttpContext.Current.Items[styleID] == null)
{
HtmlLink htmlLink = new HtmlLink();
htmlLink.Href = href;
htmlLink.Attributes.Add("rel", "stylesheet");
htmlLink.Attributes.Add("type", "text/css");
page.Header.Controls.Add(htmlLink);
HttpContext.Current.Items[styleID] = true;
}
}