472,796 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

Dynamically switching a background image

I am creating a website using .Net v2.0 and c# and I have a problem with background images.

I want to dynamically change the background image on the page, depending on data in the SQL database. If I place an <asp> label after the <body> tag, within one of the .NET containers, then it is easy to get the c# code to dynamically change the background image by placing suitable HTML on the label. The problem is that the background image does not replicate itself down through the whole screen, but stops at the end of the HTML content. In contrast, the background colour, which is set within the <body> tag does cover the whole screen as required. Therefore I concluded that the background image needs to be placed within the <body> tag. Unfortunately, the Visual Web Developer will not allow me to place an <asp> label within the <body> tag itself. I also tried placing an <asp> label in the header, with the idea that I could dynamically switch the CSS file, but that is not allowed either. The only way I can think of is to add a series on <br /> tags at the end of the file to stretch the content down to fill the screen, but this causes other problems, such as unwanted scrolling. Has anyone got any ideas, other than using php which is much more flexible?

Many thanks

ChrisAtWokingham
Sep 20 '07 #1
6 3366
Plater
7,872 Expert 4TB
Why not set the background of the page and not of a label?
Sep 20 '07 #2
Sounds good, but how do you do it? (I found another similar question, and the answer was to set the body attributes, using an ID in the body tag, but, when using masterpages, the <body> is on a different page.)

regards,

ChrisAtWokingham
Sep 24 '07 #3
Plater
7,872 Expert 4TB
Can a masterpage have a css file linked? (or in the head section?)

Because you can set the background image in CSS
Sep 24 '07 #4
Many thanks for your interest.

I am already setting the background image via CSS. The problem is switching it to a different image under program control.
Oct 2 '07 #5
Plater
7,872 Expert 4TB
You can manipulate the STYLE property of objects in your backend code.
Try that?
Oct 2 '07 #6
Many thanks,

I have got it all to work as follows:

In the Master page add the following javascript:

<script type="text/javascript">
function set_background(ChartType)
{
{
if (ChartType == "Demo")
{
document.body.style.background="#FCEFC3 url('images/Demo_Watermark.gif')";
}
if (ChartType == "Working")
{
document.body.style.background="#FCEFC3 url('images/Working_Watermark.gif')";
}
}
</script>


In the HTML body, add the following:

<asp:Label ID="Draw_Chart" runat="server" />

In the C# code, add the following:

if (Choice == "Demo")
{
Draw_Chart.Text = "<script type=\"text/javascript\" language=\"javascript\">set_background('Demo')</script>";
}
if (Choice == "Working")
{
Draw_Chart.Text = "<script type=\"text/javascript\" language=\"javascript\">set_background('Working')</script>";
}
Oct 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
1
by: antishok | last post by:
Hi, I'm writing a page which has a somewhat similar folder tree to that of the windows explorer, where each folder is made of a <SPAN> tag consisting of the folder image (closed or open) and the...
13
by: Jon Yeager | last post by:
I need to display a bunch of pictures that are all of various dimensions into a fixed dimension space, like MSN Messenger does with its user photos in the chat windows. Forcing image dimensions...
1
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or...
4
by: Chris Mahoney | last post by:
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...
5
by: Jerry Camel | last post by:
I am interacting with an OCX on the client side. In the Onload event of the page, I am checking a property of the OCX: Is the port open or closed. If the port is open, I want a certain image to...
5
by: GU | last post by:
Is it possible to use an simple cgi script to select one graphic dynamically and use this one as background image? if using <body background="/httpdocs/pics/test.jpg"> blah </body> i'll get...
12
by: Mark Rae | last post by:
Hi, It's easy enough for a child page to manipulate its MasterPage's header simply by modifying the MasterPage thus: <header runat="server"> .... .... </header>
3
by: vartana | last post by:
I will be getting the background url dynamically using ajax and html. I have set an id=boxFooter_002 to my div and have ...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.