Set Image to be Background of a div Element

I currently have a website wherby I upload an image to my database

My code then retrieves this image and sets the asp image to the url of that image:
imageProductDetail.ImageUrl = "ImageViewer.ashx?ImageID=" + getProduct.Product.ImageID.ToString();
<asp:Image ID="imageProductDetail" runat="server" CssClass="asp_image"  />
This works fine, but What I would like to do instead is create a div called imageProductDetail and then set the css background of that div to be the image url
Is this possible?
-1
adamargyle
5/4/2009 10:00:55 PM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 6 followers.

💬 3 Replies
👁️‍🗨️ 3378 Views



Well, you could set the "style" value of the Attributes collection of the div element:
 
myDiv.Attributes[&quot;style&quot;] = &quot;background-image:url(&quot;+myImgPath+&quot;); background-repeat:no-repeat;&quot;;
 This should work for the most part.  The only real drawback I see is if you have some inline styles set for the div, this declaration will overwrite those.  This can be easily averted if you apply a css class to the div to maintain the basic styling of the div, and rely on the inline styling for the specifics.

I never lose, some people are just better than me at winning.
-1
AceCorban
5/4/2009 11:18:01 PM

http://madskristensen.net/post/Reduce-the-weight-of-stylesheets-by-3525-at-runtime.aspx
How about make a generic handler to serve a special css file that has a special class name that the css url property is dynamically created based on the image ID you pass into the handler?

- William

Please mark the most helpful reply/replies as "Answer".

Give some of my PWSK modules a try.
1
whighfield
5/4/2009 11:29:27 PM
-1
shahed
5/5/2009 12:32:52 AM
Reply: