title: Change form color in ASP.NET
body: <p>Hey guys I'm writing a simple web program to get my feet wet in C#.Net and ASP.Net and I'm a little confused.</p>
  
  <p>basically what I want to do is have a drop down box where the user can select the color they want the background of the page to be, but I can't find the property to do it dynamically like that.</p>
  
  <p>not that it matters but I'm using visual studio 2010.</p>
  
  <p>Any ideas?</p>
  
  <p>Please and thanks!</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  public partial class _Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
  
      }
      protected void cmdSubmit_Click(object sender, EventArgs e)
      {
          if (txtName.Text == "")
          {
  
          }
          else
          {
              lblName.Visible = true;
              lblName.Text = "Well hello there " + txtName.Text + "!";
              lblColor.Visible = true;
              ddlColors.Visible = true;
          }
      }
      protected void ddlColors_SelectedIndexChanged(object sender, EventArgs e)
      {
          int strDdlValue = Convert.ToInt32(ddlColors.SelectedValue);
          switch (strDdlValue)
          {
              case 1:
                  Body.Style["background-color"] = "Red";
                  break;
              case 2:
                  Body.Attributes["bgcolor"] = "blue";
                  break;
              case 3:
                  Body.Attributes["bgcolor"] = "magenta";
                  break;
              case 4:
                  Body.Attributes["bgcolor"] = "green";
                  break;
              default:
                  break;
          }
          lblBye.Visible = true;
      }
  }
  </code></pre>
  
  <p>SOURCE:</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body id="Body" bgcolor="#3366ff" runat="server"&gt;
  &lt;form id="form1" runat="server" visible="True"&gt;
  &lt;div align="center" style="font-size: medium; font-weight: bold" &gt;
  
      &lt;asp:Label ID="lblWelcome" runat="server" Text="Welcome to WebGreeting!"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="lblInstruction1" runat="server" 
          Text="Please enter your name in the text box below:"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
      &lt;asp:TextBox ID="txtName" runat="server"&gt;&lt;/asp:TextBox&gt;
  &amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:Button ID="cmdSubmit" runat="server" onclick="cmdSubmit_Click" Text="Submit!" /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="lblName" runat="server"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="lblColor" runat="server" Text="What's your favorite color?" 
          Visible="False"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:DropDownList ID="ddlColors" runat="server" 
          onselectedindexchanged="ddlColors_SelectedIndexChanged" Visible="False"&gt;
          &lt;asp:ListItem&gt;&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;Red&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;Green&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;Blue&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;Yellow&lt;/asp:ListItem&gt;
      &lt;/asp:DropDownList&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Label ID="lblBye" runat="server" Text="I hope you had a nice day!" 
          Visible="False"&gt;&lt;/asp:Label&gt;
      &lt;br /&gt;
  
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>