<p>The <a href="http://msdn.microsoft.com/en-us/library/kx145dw2.aspx" rel="noreferrer">ClientScriptManager.RegisterClientScriptInclude</a> method allows you to register a JavaScript reference with the Page object (checking for duplicates).</p>

<p>Is there an equivalent of this method for CSS references?</p>

<p>Similar questions apply for <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx" rel="noreferrer">ClientScriptManager.RegisterClientScriptBlock</a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptresource.aspx" rel="noreferrer">ClientScriptManager.RegisterClientScriptResource</a></p>

[{'answer_id': 54707, 'author': 'Gulzar Nazim', 'author_id': 4337, 'author_profile': 'https://Stackoverflow.com/users/4337', 'pm_score': 2, 'selected': False, 'text': '<p>I have used css files as <a href="http://aspalliance.com/726" rel="nofollow noreferrer">Embedded resources</a>. </p>\n'}, {'answer_id': 112189, 'author': 'CMPalmer', 'author_id': 14894, 'author_profile': 'https://Stackoverflow.com/users/14894', 'pm_score': 3, 'selected': False, 'text': '<p>You can add header links to CSS files in ASP.Net codebehind classes like this:</p>\n\n<pre><code>HtmlLink link = new HtmlLink();\nlink.Href = "Cases/EditStyles.css";\nlink.Attributes.Add("type", "text/css");\nlink.Attributes.Add("rel", "stylesheet");\nthis.Header.Controls.Add(link);\n</code></pre>\n\n<p>You can iterate through the header controls beforehand to see if it is already there. The example shown is from a Page_Load in one of my projects and is inside a conditional expression that only adds the EditStyles.css if the page is supposed to be in "Edit" mode.</p>\n\n<p>For ClientScriptManager.RegisterClientScriptBlock and ClientScriptManager.RegisterClientScriptResource, they have equivalent functions for checking if they\'ve already been registered (e.g., IsClientScriptrResourceRegistered).</p>\n'}, {'answer_id': 112736, 'author': 'Herb Caudill', 'author_id': 239663, 'author_profile': 'https://Stackoverflow.com/users/239663', 'pm_score': 4, 'selected': True, 'text': "<p>Short answer: no. You could certainly roll your own functions (as CMPalmer suggests) to take CSS embedded resources (as Gulzar suggests) and embed them on the page.</p>\n\n<p>As a best-practice matter, though, I'm not sure why you would want to do this. If you're making a reusable control that has a lot of CSS styling, my advice would be to just hard-code the class names into the standards-compliant output of your control, and ship the control accompanied by a suggested stylesheet. This gives your users/customers the option of overriding your suggested styles to fit their needs, and in general allows them to manage their CSS setup as they see fit. </p>\n\n<p>Separating style from markup is a Good Thing - you're already headed down the right path in avoiding the various built-in ASP.NET style attributes, but you should take it all the way and keep the CSS out of your .dll.</p>\n"}, {'answer_id': 112745, 'author': 'Herb Caudill', 'author_id': 239663, 'author_profile': 'https://Stackoverflow.com/users/239663', 'pm_score': 0, 'selected': False, 'text': '<p>One more thought: You might want to consider "namespacing" your class names to avoid collisions with common class names that your consumers might already be using. E.g.</p>\n\n<pre><code>&lt;div class="SmillerControls_Toolbar"&gt;\n    &lt;a class="SmillerControls_Button" ...&gt;...&lt;/a&gt;\n    ...\n&lt;/div&gt;\n</code></pre>\n\n<p>or you could wrap the whole thing in a single "namespace" class and then write your CSS to that:</p>\n\n<pre><code> &lt;div class="SmillerControls"&gt;\n     &lt;div class="Toolbar"&gt;\n          &lt;a class="Button" ...&gt;...&lt;/a&gt;\n     &lt;/div&gt;\n &lt;/div&gt;\n</code></pre>\n\n<p>your CSS would be like</p>\n\n<pre><code> div.SmillerControls div.Toolbar\n {\n     ...\n }\n\n div.SmillerControls div.Toolbar a.Button\n {\n     ...\n }\n</code></pre>\n'}, {'answer_id': 3241134, 'author': 'guillem', 'author_id': 351975, 'author_profile': 'https://Stackoverflow.com/users/351975', 'pm_score': 0, 'selected': False, 'text': '<p>What I do is use an </p>\n\n<pre><code>&lt;asp:Literal id="cssliteral" runat="server" /&gt; \n</code></pre>\n\n<p>in head and then a StringBuilder on PageLoad that contains the dynamic css script.</p>\n\n<pre><code>StingBuilder str = new StringBuilder();\nstr.Append("&lt;style type="text/css"&gt;");\nstr.Append(".myclass {background-color:#" + mycolor);\nstr.Append("&lt;/style&gt;");\n\ncssLiteral.Text = str.ToString();\n</code></pre>\n'}, {'answer_id': 3522817, 'author': 'mindless', 'author_id': 425364, 'author_profile': 'https://Stackoverflow.com/users/425364', 'pm_score': 2, 'selected': False, 'text': '<p>Just check for the existance of a registered script, and if you find that it\'s not there, then you will known this is the first time your control is being created. At which point you can just drop a literal control into your page that points to the css file you want.</p>\n\n<pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n    With Page.ClientScript\n        If Not .IsClientScriptIncludeRegistered("JQuery") Then \n            .RegisterClientScriptInclude("JQuery", "Scripts/jquery-1.4.2.min.js")\n            Dim l As New Literal()\n            l.Text = "&lt;link href=\'Uploadify/uploadify.css\' rel=\'stylesheet\' type=\'text/css\' /&gt;"\n            sender.controls.add(l)\n        End If\n    End With\nEnd Sub\n</code></pre>\n\n<p>Hope this helps someone.</p>\n'}]
['https://Stackoverflow.com/questions/54658', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/247/']