Changing CSS Background Dynamically (VB)

C

Chris Mahoney

Hi

Currently I am setting the background image of my page by using the
following code:

<style type="text/css">
BODY { BACKGROUND-IMAGE: url(myimage.jpg) }
</style>

What I would like to do is change the background image dynamically. My guess
was to use the Attributes.Add function, but while I can do something like
Button1.Attributes.Add, I can't figure out how to apply attributes to the
entire page.

Am I on the right track or should I being doing something else?

Thanks
Chris
 
C

Craig Deelsnyder

Hi

Currently I am setting the background image of my page by using the
following code:

<style type="text/css">
BODY { BACKGROUND-IMAGE: url(myimage.jpg) }
</style>

What I would like to do is change the background image dynamically. My
guess
was to use the Attributes.Add function, but while I can do something like
Button1.Attributes.Add, I can't figure out how to apply attributes to the
entire page.

Am I on the right track or should I being doing something else?

Thanks
Chris

You can make the STYLE tag a server control and then alter it from
code-behind (you can do this with just about any tag in the doc).

My example is changing background-color:
<!-- add an id="" and runat="server" to the tag -->
<style id="hgcStyle" runat="server">
.tb { BACKGROUND-COLOR: red }
</style>

code-behind:
'//you have to declare the control variable yourself, just like the other
controls
Protected WithEvents hgcStyle As
System.Web.UI.HtmlControls.HtmlGenericControl

'//now you can access the tag, e.g.
hgcStyle.InnerText = ".tb {background-color: " & TextBox1.Text & "}"
 
T

Tom Dacon

Chris Mahoney said:
Don't worry, I figured it out :)

OK, so you figured it out. How nice for you. How about sharing the solution
with the group, so that when someone else has a similar problem and searches
groups.google.com, they won't just come across a thread that promises a
solution but ends in nothing but a smiley?

We're all in this together, amigo.

Tom Dacon
Dacon Software Consulting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top