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

Discussion in 'ASP .Net Web Controls' started by el bilo, Sep 27, 2003.

  1. el bilo

    el bilo Guest

    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
     
    el bilo, Sep 27, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:15a801c384bb$1366a270$...
    > 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
     
    Alessandro Zifiglio, Sep 27, 2003
    #2
    1. Advertising

  3. el bilo

    Larry Guest

    Thanks for your help. it worked perfectly!

    -Larry


    "Alessandro Zifiglio" <> wrote in message
    news:mmddb.1674$...
    > 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" <> wrote in message
    > news:15a801c384bb$1366a270$...
    > > 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

    >
    >
     
    Larry, Sep 28, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    584
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    580
    Alex Papadimoulis
    Dec 12, 2003
  3. =?Utf-8?B?bXN1aw==?=

    Using one webform to set a value on another webform

    =?Utf-8?B?bXN1aw==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    531
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2006
  4. =?Utf-8?B?Vk1J?=

    Moving value from popup Webform to main Webform?

    =?Utf-8?B?Vk1J?=, Oct 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    626
    GroupReader
    Oct 9, 2006
  5. Luqman
    Replies:
    2
    Views:
    705
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 11, 2007
Loading...

Share This Page