Inline code within HEAD section of ASP Web Form

Posted by geekrutherford on Geeks with Blogs See other posts from Geeks with Blogs or by geekrutherford
Published on Mon, 31 Jan 2011 16:23:00 GMT Indexed on 2011/01/31 23:27 UTC
Read the original article Hit count: 362

Filed under:

 

Today I needed to include inline code within the HEAD section of an Web Form in order to dynamically include stylesheets based on the theme set for the application.


 

Below is an example:

     <link href="../../Resources/Themes/<% = Page.Theme %>Grid.Default.css" rel="stylesheet" type="text/css">


 

Upon saving and viewing the page I noted that the code was not being interpreted and instead was being treated as a string literal.  How to get around it?  Add a panel control in the HEAD section and place the links to the stylesheets as in the example above within the panel.  For whatever reason, ASP.NET does not want to interpret inline code in the HEAD section but will allow you to add .NET controls in the HEAD section.

© Geeks with Blogs or respective owner