itinfo7
asked on
Add BackgroundImage for DIV from .net Backend
Hello Experts,
I have Div in Front end like this.
<div id="frontDiv" style="float:left;">
I want to give background image from .net backend Like this
DivFront.Attributes.Add("s tyle", "background-Image:url(http://localhost/Templates/Products/POD/VCA/dog.JPG)");
but it's not taking background image for that DIV.I really don't know is there any other method for giving background-image for DIV.
Please guide me in this.
I have Div in Front end like this.
<div id="frontDiv" style="float:left;">
I want to give background image from .net backend Like this
DivFront.Attributes.Add("s
but it's not taking background image for that DIV.I really don't know is there any other method for giving background-image for DIV.
Please guide me in this.
Add runat="server" and then you will be able to access it in your code behind file:-
<div id="frontDiv" style="float:left;" runat="server">
Next check that this url does show up the image and not 404 error.
<div id="frontDiv" style="float:left;" runat="server">
Next check that this url does show up the image and not 404 error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, the code behind needs to be written as below:
frontDiv.Attributes.Add("s tyle", @"background-Image:url(""" + Server.MapPath("~/Template s/Products /POD/VCA/d og.JPG") + @""");
Here the Templates directory should be in your root.
frontDiv.Attributes.Add("s
Here the Templates directory should be in your root.
Is there any specific reason for assigning background color to div from code behind?
Better approach is using CSS.
Here is exmple:
Open in new window
Is still you want to use it from code behind then you have to make that div as server side control so that you can access it from code behind or simply you can take Panel control and use it's "BackImageUrl" property to assign background image.