?
Solved

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

Posted on 2007-11-28
3
Medium Priority
?
1,424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
cmhunty earned 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 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