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. Setting background color in asp.net form

Setting background color in asp.net form

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestionlearning
4 Posts 2 Posters 6 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.
  • J Offline
    J Offline
    JGranborg
    wrote on last edited by
    #1

    As a beginner in asp.net, I have a very simple problem. How do I set the background color dynamic from my c# code in an asp.net web application. Simple but very frustrating. Jørgen

    M 1 Reply Last reply
    0
    • J JGranborg

      As a beginner in asp.net, I have a very simple problem. How do I set the background color dynamic from my c# code in an asp.net web application. Simple but very frustrating. Jørgen

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

      Hi there. One approach would be to assign the "runat='server'" attribute and an id attribute to the html literal <body> tag. Then in code you can set the bgColor attribute based on the <body> tag's id to dynamically change the background color.

      <%@Page language="C#" %>

      <script runat="server">
      void Page_Load(Object o, EventArgs e)
      {
      // dynamically change the background color
      // of the page
      pageBodyTag.Attributes["bgColor"]="#D0D0B8";
      }
      </script>

      <html>
      <head>
      </head>

      <body id="pageBodyTag" runat="server">
          <h3>Background Color on Page</h3>
          <p>Isn't this fun?</p>
      </body>
      

      </html>

      J 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. One approach would be to assign the "runat='server'" attribute and an id attribute to the html literal <body> tag. Then in code you can set the bgColor attribute based on the <body> tag's id to dynamically change the background color.

        <%@Page language="C#" %>

        <script runat="server">
        void Page_Load(Object o, EventArgs e)
        {
        // dynamically change the background color
        // of the page
        pageBodyTag.Attributes["bgColor"]="#D0D0B8";
        }
        </script>

        <html>
        <head>
        </head>

        <body id="pageBodyTag" runat="server">
            <h3>Background Color on Page</h3>
            <p>Isn't this fun?</p>
        </body>
        

        </html>

        J Offline
        J Offline
        JGranborg
        wrote on last edited by
        #3

        Thanks a lot, as a newbie I´d never get it to work, with your Page_Load overwrite but > and then having a GetColor() in my page class worked. You got me on the right track. Thanks a lot Jørgen Granborg

        M 1 Reply Last reply
        0
        • J JGranborg

          Thanks a lot, as a newbie I´d never get it to work, with your Page_Load overwrite but > and then having a GetColor() in my page class worked. You got me on the right track. Thanks a lot Jørgen Granborg

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

          I like your idea better. Glad you got figured it out.

          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