Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to set background color?

How to set background color?

Scheduled Pinned Locked Moved ASP.NET
questiontutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    ben2
    wrote on last edited by
    #1

    Hi, This is a newbie question. How can I set the background color of the web form page from code behind page model? I want something like: private void Page_Load(object sender, System.EventArgs e) { //set the background color of the page here } I dont want to use any in page scripting for this.

    T M P 3 Replies Last reply
    0
    • B ben2

      Hi, This is a newbie question. How can I set the background color of the web form page from code behind page model? I want something like: private void Page_Load(object sender, System.EventArgs e) { //set the background color of the page here } I dont want to use any in page scripting for this.

      T Offline
      T Offline
      Thang T
      wrote on last edited by
      #2

      I don't remember exactly, but you can use the property in the Page Page.BackColor = Color.Red Ich liebe .NET :)

      1 Reply Last reply
      0
      • B ben2

        Hi, This is a newbie question. How can I set the background color of the web form page from code behind page model? I want something like: private void Page_Load(object sender, System.EventArgs e) { //set the background color of the page here } I dont want to use any in page scripting for this.

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        Hi there. You can set the bgcolor of the body element directly -

        <body bgcolor="#FFC9B8">

        or you can create a css <style> for the page:

        <html>
        <head>
        <style>
        body {background-color: #FFC9B8;}
        </style>
        </head>
        <body>
        ...
        </body>
        </html>

        Or, if you do want to set it in the server-side Page_Load, you can add an id attribute and runat="server" to the <body> tag, then reference it server-side:

        <script runat="server">
        void Page_Load(object sender, System.EventArgs e)
        {
        myPageBody.Attributes["bgcolor"] = "#FFC9B8";
        }
        </script>
        <html>
        <body id="myPageBody" runat="server">
        ...
        </body>
        </html>

        1 Reply Last reply
        0
        • B ben2

          Hi, This is a newbie question. How can I set the background color of the web form page from code behind page model? I want something like: private void Page_Load(object sender, System.EventArgs e) { //set the background color of the page here } I dont want to use any in page scripting for this.

          P Offline
          P Offline
          playout
          wrote on last edited by
          #4

          Or why not use a cookie to set the value - by doing this, the colour can be set from somewhere else, and be used throughout the site. I am not to sure how to do this in C#, as I am doing vb.net....

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups