By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

Changing CSS Background Dynamically (VB)

P: n/a
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

Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Don't worry, I figured it out :)

Chris

On 30/8/04 11:04 AM, in article BD***************@spam.me, "Chris Mahoney"
<do**@spam.me> wrote:
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


Nov 18 '05 #2

P: n/a
On Mon, 30 Aug 2004 11:04:00 +1200, Chris Mahoney <do**@spam.me> wrote:
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 & "}"

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #3

P: n/a
On Mon, 30 Aug 2004 13:50:38 +1200, Chris Mahoney <do**@spam.me> wrote:
Don't worry, I figured it out :)

Chris


TOO LATE! Reply is coming :-)

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #4

P: n/a

"Chris Mahoney" <do**@spam.me> wrote in message
news:BD58E12E.6FF%do**@spam.me...
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


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.