Changing CSS Background Dynamically (VB)

  • Thread starter Thread starter Chris Mahoney
  • Start date Start date
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
 
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 & "}"
 
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
 
Back
Top