2

This is a NEW question and it is highly related to this topic: How to reference embedded images from CSS? For whatever reason I am forced to post a new thread here, so please see the original thread to understand what the issue is here.

I want to create an asp.net server control which bringt an embedded .CSS field and a few embedded image files. From the css I want to use the background-image command to provide the output HTML using this class with the required images.

I can't get any of the pointed approaches to work.

I tried all variations...:

[assembly: System.Web.UI.WebResource("MapBG.png", "image/png")] 
[assembly: System.Web.UI.WebResource("myWebControls.Resources.MapBG.png", "image/png")]  

background-image: url(<%=WebResource("myWebControls.Resources.MapBG.png")%>);   
background-image: url('<%= Page.ClientScript.GetWebResourceUrl(typeof(myWebControls.ElanStatusMap.ElanStatusMap), "MapBG.png") %>'); 
background-image: url('<%= Page.ClientScript.GetWebResourceUrl(typeof(myWebControls.ElanStatusMap.ElanStatusMap), "myWebControls.Resources.MapBG.png") %>'); 

Nothing works. Any more ideas on this?

Community
  • 1
  • 1
Magier
  • 437
  • 1
  • 6
  • 18

1 Answers1

4

CSS pages are not rendered like aspx pages, so you can't put server blocks in them.

Instead, you can include that CSS in your ASPX page in a <style> block and then you can use this mechanism.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Hey. Since the css should be shipped with my control, not with the page that consumes th control, I can't do it this way. Alternatively I have to server side output all my css from the control's code File? – Magier Sep 30 '11 at 08:34
  • 1
    @Magier - Yes. You would hvae to inject a style block into the page the control is placed on. This is the way the asp.net built-in controls do it. You could also develop an HttpHandler or Module to intercept css calls, but that's just a huge headache. – Erik Funkenbusch Sep 30 '11 at 08:41
  • Good suggestion, it works sucking all css lines into a stringbuilder and outputting it from my codefile into the result html! Thanks. But one more simple question is there: I actually output my styles from the protected override void RenderContents method, which makes the style tag placed in the middle of the body tag, how can I output this into the html header? There is this protected override void OnPreRender handler thich seems to be able to do so but in this context there is no required HtmlTextWriter object available, which I am not able to create on my own at the moment... thanks!!! – Magier Sep 30 '11 at 09:13
  • You would require the pages to put `runat="server" on the title element, then insert a literal into the controls of the title control. – Erik Funkenbusch Sep 30 '11 at 14:52