How do I set the webForm's background at runtime?

E

el bilo

I working on a project that creates customised web pages
from a templete and need to be able to have the
codebehind set the page's bacground color and text color
from values fetched from a database.

Problem I'm having is I haven't found a way to access the
DOM style properties for the document (or body) from
asp.net

Any suggestions?

-Larry
 
A

Alessandro Zifiglio

you cant directly access client side code from the server and asp.net is
server side. You can however combine the both by injecting into the page
clientside script.
What you want to do is very simple and you should try swapping css files
server side, that is in asp.net code before you render the page to the
client.

You might want to create a style sheet link reference with an id attribute
and runat="server" in your .aspx page, in html view that is, this way you
can retrieve it in your code behind and pass a seperate css file.
<link id="cssfile1" runat="server" type="text/css" rel="stylesheet" />

and then in your code behind declare an HtmlGenericControl like this :
Public cssfile1 As HtmlGenericControl

Now you can access your stylesheet reference from code and pass a seperate
stylesheet to it everytime you want to change styles.
cssfile1.Attributes.Add("href", Me.ResolveUrl("../css/mainstylesheet.css"))

You can perform this on individual elements by writing inline css whereas to
using a stylesheet or along with the style sheet. This is not a detailed
over view but however it should put you on the right track. Because you are
collecting items from your DB you might want to use inline style sheets
instead. To get what you want working maybe an external stylesheet is not
what your looking for, instead you should add an id attribute to your body
element with runat="server" and declare it in your code behind like you did
with the css file and add an inline style attribute to it, like
style="background-color: #000; color: #ccff66"
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top