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?
Well, you could set the "style" value of the Attributes collection of the div element:
myDiv.Attributes["style"] = "background-image:url("+myImgPath+"); background-repeat:no-repeat;";
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.
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?
Please mark the most helpful reply/replies as "Answer".
Give some of my PWSK modules a try.