Solved

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

Posted on 2007-11-28
3
1,405 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 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

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

Suggested Solutions

Title # Comments Views Activity
Aspx calendar pop up control 3 38
Connect Gridview column to Textbox in C# 2 55
How do I "share" on social sites? 2 38
SQL query joining 6 tables in asp.net 4 30
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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