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. 3 followers. Follow

3 Replies
1640 Views

Similar Articles

[PageSpeed] 7

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.
-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:

Similar Artilces:

For interrupting.web form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form
Web Form Resized by position of the div : if div can't dispaly all (such as only top part , then web form heithten the heght),resize the web form ! Because of my pool English, if you can't see , I will explain more ! ThanksGambler is the real life I guess you mean when form grows it also grow parent div element. This is normal. If you want div to stay fixed size and rather clip the form and maybe show a scrollbar, look at overflow property in CSS.Thanks------------------------------------------------------------This posting is provided "AS IS" with no warranties, and confers no ...

Web form background image
Using visual web developer, I have an image set using body background = "addresspath.jpg"... which is fine when i'm designing the form, the image appears. The web form then builds perfectly, but when i start it the image goes away again. I've gone throught the format menu, style, and back ground and set it there also, and again it works in design view but disappears when I start without debugging. Any help?!?!?       hi,   is that the file "addresspath.jpg"  placed under the same folder?.if no then u have to specify the relative path instead...

help building this into a string: <div style="background-image: url('303.jpg'); background-repeat: no-repeat;">this is place holder<br />of this image</div>
I want to build this difinition into a javascriptp string for insertion like var str = '<div id="tempewoiew{1}" style="background-image: url("'"/BCW_Web/PhotoFeeders/GetNewImagePoolPhotoThumbNail.aspx?ImagePoolPhotoIndex={2}"'"); background-repeat: no-repeat;">this is place holder<br />of this image</div>';   element.innerHTML = str; but the part url('303.jpg'); screws me up...   its the quotation marks or the semi colon..??? i dont know how to express the quotation marks in this statement ...

Background image and web form size
Hi All! I've put a background image in my web form and I want the web form to be the same size as the image. But at the moment the background image keeps repeating itself! Is there anyway to set the web form to a fixed size based on the background image? I also have a datagrid that keeps expanding so am not sure how to deal when it becomes larger than the background image. Any help would be great, Thanks! Check out this page, it should help you to implement a background image: http://www.tizag.com/cssT/background.php Jared LivingstonMrLivingston.com - Livingston Family Website...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Background Image not showing
 I have a web part that I'm building for the Beer House site.  I want a background image to show up for the div in the control which it does in design view inside VS9, but when I run the site the background doesn't show.  Anyone know why?<div style="border: solid 1px black; padding: 4px; color: White; margin-bottom: 10px; font-weight: bold; background-image: url(/Images/board.jpg)"> </div>Thanks,Shawn Turns out that this code works on the production server just not on the built-in dev server.Thanks,Shawn...

trying to set attributes of a web form element dynamically
I am sure this has already been covered, but I can't seem to find it: What I am trying to do is pull info from an outside source to dynamically build form control, and attributes settings. For example: dim controlString as string dim tempColor as string dim tempAttribute as string dim tempName as string tempColor = "'#FF00FF'" tempAttribute = "BackColor" tempName = "Label1" controlString = tempName & "." & tempAttribute & " = " & tempColor So the controlString would = "Label1.BackColor = '...

VB.NET web form Image control SizeMode
The "PictureBox" control in VB.NET has a property called "SizeMode". This allows you to choose how the image will display in the picture box if it is not the same size as the picturebox. However the "image" control for a VB.NET web form (in an ASP.NET application) does not have such a property, instead all images seem to be set to "StretchImage". I want them to be set to "normal", how can I do this? I thought of building my own user control but this would be silly because there must be a simpler way....

change web form background property from code in vb.net
I have a web form in a vb.net project. The web form has both a design view and an HTML view. In the design view, the property box has a background property that can be set to an image file. This causes a background attribute to be added to the Body element in the HTML view. My question is, how do I modify the background property from program code? I can't find the object that has this property so I can set its value. On way to do it is to use 2 different style sheet and change the stylesheet in the pageload event depending on your condition. Look for an example in Report Starter Kit ...

how can i set the div on top of all athere elements on the form by js
 hello how can i set the div on top of all athere elements on the form by jssecondly how to backroun image on div by js. at the code below i get the image on the div but its see thwo like and you can see all the behind elements as well   function imgTest_onmouseover(obj) { var oDiv = document.createElement("div"); oDiv.id = obj.id + 'Temp'; var oImg = document.createElement("img"); oImg.src = obj.src; oDiv.style.position = 'absolute'; oDiv.style.width = 200 + 'px'; oDiv.style.height = 200 + '...

Is that possible to setting a transparent background image for <window> element?
I want to preserve the aero effect of the Window, but I also need to customize the UI, so I need a transparent background image for the top level <window> elemetn, is that possible? On Sun, Aug 17, 2014 at 3:41 PM, Yonggang Luo <luoyonggang@gmail.com> wrote= : > I want to preserve the aero effect of the Window, but I also need to > customize the UI, so I need a transparent background image for the top > level <window> elemetn, is that possible? > Yes. Firefox does this. You need to set -moz-appearance:none on the <window> as well as making sure ...

superreview requested: [Bug 292191] If using background-image in an element, we should reverse the result of reverse selection algorithm when the element's foreground color and background color is sim
Masayuki Nakano (Mozilla Japan) <masayuki@d-toybox.com> has asked Boris Zbarsky <bzbarsky@mit.edu> for superreview: Bug 292191: If using background-image in an element, we should reverse the result of reverse selection algorithm when the element's foreground color and background color is similar https://bugzilla.mozilla.org/show_bug.cgi?id=292191 Attachment 192919: Patch rv1.0 https://bugzilla.mozilla.org/attachment.cgi?id=192919&action=edit ...

superreview cancelled: [Bug 292191] If using background-image in an element, we should reverse the result of reverse selection algorithm when the element's foreground color and background color is sim
Masayuki Nakano (Mozilla Japan) <masayuki@d-toybox.com> has cancelled Masayuki Nakano (Mozilla Japan) <masayuki@d-toybox.com>'s request for superreview: Bug 292191: If using background-image in an element, we should reverse the result of reverse selection algorithm when the element's foreground color and background color is similar https://bugzilla.mozilla.org/show_bug.cgi?id=292191 Attachment 192919: Patch rv1.0 https://bugzilla.mozilla.org/attachment.cgi?id=192919&action=edit ------- Additional Comments from Masayuki Nakano (Mozilla Japan) <masayuki@d-...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Web resources about - Set Image to be Background of a div Element - asp.net.web-forms

Background Music (album) - Wikipedia, the free encyclopedia
^ Morris, Kurt. " Background Music – Overview" . Allmusic . Rovi Corporation . http://allmusic.com/album/background-music-r642918 . Retrieved ...

Android App OStream Speeds Up Facebook Experience By Synchronizing Content In Background
Facebook’s newly revamped Android application was rebuilt with a focus on speed, and startup oStream wants to help users of devices on that operating ...

Background for Dick Armey’s Endorsement of “Nothing for the Nation”
To truly grasp the profound nature of Dick Armey’s endorsement of Nothing for the Nation: Who Got What Out of Iraq, one must understand the events ...

Parse launches analytics tool, background jobs feature at first Developer Day conference
Parse , the Facebook-owned app development platform, held its first Developer Day conference in San Francisco Thursday, and the company launched ...

Easy Background Tasks in ASP.NET
As I work on the badge implementation for Stack Overflow, I needed a way to call the code that detects and awards the badges out of band. Traditionally ...

Wallpaper Studio Pro HD - Themes & Backgrounds for iPad on the iTunes App Store
Get Wallpaper Studio Pro HD - Themes & Backgrounds on the App Store. See screenshots and ratings, and read customer reviews.

Malcolm Turnbull uses shared business background to reset Indonesian relations
Malcolm Turnbull has used his first major overseas visit to reset Australia's fractious relationship with Indonesia, leveraging his common personal ...

More to selecting political background music than indiscriminate meandering
Gathering a song to use as a protest weapon can backfire.

Obama to Veto Bill Requiring Background Checks On Syrian Refugees; France Demands Tighter Controls, EU ...
... requirements " that would harm efforts to assist some of the world's most vulnerable people. The bill would add a new requirement for FBI background ...

Ben Carson hits media amid background questions - Business Insider
"What happened to investigative reporting?" CBS Retired neurosurgeon Ben Carson, under increased scrutiny over his personal background this ...

Resources last updated: 11/29/2015 3:12:02 PM