Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How do I set the webForm's background at runtime?

Reply
Thread Tools

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

 
 
el bilo
Guest
Posts: n/a
 
      09-27-2003
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
 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      09-27-2003
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"




"el bilo" <(E-Mail Removed)> wrote in message
news:15a801c384bb$1366a270$(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Larry
Guest
Posts: n/a
 
      09-28-2003
Thanks for your help. it worked perfectly!

-Larry


"Alessandro Zifiglio" <(E-Mail Removed)> wrote in message
news:mmddb.1674$(E-Mail Removed)...
> 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"
>
>
>
>
> "el bilo" <(E-Mail Removed)> wrote in message
> news:15a801c384bb$1366a270$(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
DIV background-repeat background-image? For shadow effect jc ASP .Net 3 03-19-2008 04:19 PM
not able to click on background tab and backgrounds in properties to change the background. rex Computer Support 2 12-06-2006 02:26 AM
Background transparent when 'background' is used JWL HTML 4 09-26-2006 05:37 PM
Background Check - Background search - People search mason66 ASP .Net 0 07-27-2006 10:20 AM



Advertisments