Solved

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

Posted on 2007-11-28
3
1,378 Views
Last Modified: 2012-06-21
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,
0
Comment
Question by:jimbona27
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
cmhunty earned 300 total points
ID: 20364764
You can set the background image by setting the style attribute of the div element:
        Dim strImageUrl As String = "URL_To_Image"

        panel1.Attributes.Add("style", "background-image=url(" & strImageUrl & ")")

Open in new window

0
 
LVL 11

Expert Comment

by:cmhunty
ID: 20364799
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.
0
 

Author Comment

by:jimbona27
ID: 20364896
ok thanks great stuff
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now