Tuesday, November 9, 2010

asp.net dynamic embedded resources

Use Case

You have an embedded css stylesheet (main.css) and background image (bg.gif). In css you would like to have smth like:

#header {
    background : #7F99BE url('reference to bg.gif') repeat-x scroll center center;
    border     : solid 1px #122A59;


First, make sure, that main.css and bg.gif are marked as Embedded Resources in property editor.
Then, make sure that they're registered to be included into assembly manifest using commands below:

[assembly: WebResource("XXX.YYY.Content.css.main.css", "text/css", PerformSubstitution=true)]
[assembly: WebResource("XXX.YYY.Content.images.bg.gif", "image/gif")]

Note, 3rd parameter PerformSubsitution=true.

Now in main.css you can use reference to bg.gif as shown below:

#header { 
    background : #7F99BE url('<%= WebResource("XXX.YYY.Content.images.bg.gif") %>') repeat-x scroll center center; 
    border     : solid 1px #122A59;

For more information, refer to excellent article about embedding resources into assembly at: 

No comments:

Post a Comment