change background image in code

G

Guest

I want to change the background image of the html page within code based on
the users selection.
I'm trying to use this in the page onload even

response.write("<body background=' & dataitem>")

but i can't get it to work. if i hard code the dataitem in it will change
but i need it to work with the item being passed in.
 
E

Eliyahu Goldin

Add javascript variable backgroundString and function onLoad() to the <head>
section:

var backgroundString;
function onLoad(){document.body.background=backgroundString}

In the html view write <body onload='onLoad()'>

In the code-behind write (c#)
Response.Write(String.Format("<script>backgroundString={0}<script>",
dataitem));

Eliyahu
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top