Link to home
Start Free TrialLog in
Avatar of jimbona27
jimbona27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

how to apply a css background-image in the code behind file

hi there,
i've come across a problem that I cant figure out looking through the options for a <div id="test" runat="server">..

I need to dynamically set a background-image to a <div>.

i have tried the following

<div <literal></literal>>
  my content
</div>

literal1.text = "style:background-image...";

(this wouldnt be a nice way of doing even if it worked)

i've also tried

<div id="panel1" runat="server">

code behind:
        panel1.ApplyStyleSheetSkin = "background-image: url()";

not sure how to use ApplyStyleSheetSkin but that was my best attempt

I could write the entire div out using a literal control I guess, like so,

<literal></literal>

literal1.text = "<div style=background-image:url...>content</div>";

but i assume there's a nicer way of doing it?  
enlighten me!
thank,
ASKER CERTIFIED SOLUTION
Avatar of cmhunty
cmhunty

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmhunty
cmhunty

Alternatively, you can remove the runat in the div:

<div id="panel1" style="background-image=url(<%=strImageURL%>)" />

and then set the variable up in the code:

Public strImageUrl As String

and then set that to anything you require.
Avatar of jimbona27

ASKER

ok thanks great stuff