tags:

views:

42

answers:

3

I got this div tag who's background image's being set in the CSS using some method like this..

Inline CSS:-

.id0, .mySprite:hover div
    {
        background-image: url(<%=GetImage()%>);
        background-repeat: no-repeat;
        width: 728px;
        height: 243px;

    }

HTML:-

<div class="id0"></div>

Now do I need to set runat=server in this div tag or not ? coz its not giving no error but was wondering may be I need to coz the image's path's being fetched from code behind...the image's not appearing in this user control

+2  A: 

Well,

  • The Runat=Server is not needed at all. The CSS is loaded / Associated on the client (in the brwoser) anyway.
  • Sorry, dude, but .CSS files are not evaluated by ASP.NET - so basically, the "url" that the browser gets is "<%=GetImage()%>", which obviously the browser can not do anything with.

Result: Does not work. CAN not work.

TomTom
how come the value returned by the method's is being shown in the CSS then ?
Serenity
changed that in the CSS and have overridden the background-image property in that div as url(<%=GetImage()%>); ...the image path appears in the page source in the div..but cant see image..runat=server's making no diff
Serenity
+1 for targeted bluntness.
RPM1984
Hold on, is this inline CSS, or an external CSS file?
RPM1984
inline css......
Serenity
Unusual - then naturally my answer is wrong. What IS shown in the generated file then? Obviously there is an error there;)
TomTom
nothing is being shownn...no image ...these are the problems I am facing now.. http://stackoverflow.com/questions/4012139/need-help-with-css-how-do-i-get-the-image-to-appear-in-the-background ...and this http://stackoverflow.com/questions/4013669/divs-background-images-position-is-not-changing-when-links-are-hovered-over-wh ... help me? :( just can't make this stupid sprite work..argh
Serenity
Try entering the full url. url(images/image.jpg); could just end up in the wrong folder. At least start with /
TomTom
+1  A: 

You are generating the css from server-side code? Or is a simple .css file? If you have .css file the code: background-image: url(<%=GetImage()%>); does not work.

And then, the css rule for div with id id0, you must define it with # not dot (#id0 not .id0)

alfdev
id0 is a class..the div's class is set to id0
Serenity
won't it work if he adds runat="server" to the css file?
BennyM
@Benny :: just tried that..not working..cant see no image still
Serenity
+1  A: 

Why do you need the server to generate the path? The image path should be relative to the css file so if your css is in project/css/style.css and image is in project/images/myimage.jpg use

background-image: url(../images/myimage.jpg);

Also, use firebug to check what's really being set as the background image. You can also try

background-image: url(../images/myimage.jpg) !important;
Michael
Could u plz check my code here ?? have made changes...http://stackoverflow.com/questions/3975148/image-wont-render-on-my-aspx-page-after-adding-master-page-if-not-changed-id-w
Serenity
Image just won't display!
Serenity