title: asp.net how to change color of asp:panel
body: <p>I'm trying to change the (back)color of a <code>panel</code> in my web application to signal a modal change. I'm using an asp.net WebForm project, with VS Express 2013 for Web. I have a web application with multiple pages, and one of these pages contains a set of three nested panels:</p>
  
  <pre><code>&lt;asp:Panel ID="ManageTemplatesPanel" runat="server" style="border-radius:3px" BorderStyle="Solid" BackColor="White" Height="1415px" Width="930px" ScrollBars="None" BorderWidth="1px"&gt;
  &lt;asp:Panel ID="BigInsetGrayPanel" runat="server" style="border-radius:3px" BackColor="Silver" BorderStyle="Solid" BorderWidth="1px" Height="1275px" Width="910px" &gt;
  &lt;asp:Panel ID="SelectClientsWhiteInsetPanel" runat="server" style="margin-left:20px;margin-right:20px;border-radius:3px" BackColor="White" Height="465px" BorderStyle="None"&gt;
  </code></pre>
  
  <p>Inside each panel there are many controls - text boxes, gridviews, buttons, etc.
  Then there is a set of closing tags for the panels.</p>
  
  <p>I have a <code>CheckBoxList</code> control with three checkboxes inside:</p>
  
  <pre><code>&lt;asp:CheckBoxList ID="IncludeCheckBoxList" runat="server" BackColor="White" BorderStyle="None" CssClass="cssIncludeCheckBoxList" Font-Names="Arial" Font-Size="Small" ForeColor="Black" RepeatDirection="Horizontal" RepeatLayout="Flow" Height="28px" AutoPostBack="True" OnSelectedIndexChanged="IncludeCheckBoxList_SelectedIndexChanged"&gt;
      &lt;asp:ListItem Selected="True"&gt;Sent Client List&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Selected="True"&gt;Notification Time&lt;/asp:ListItem&gt;
      &lt;asp:ListItem Selected="True"&gt;Message&lt;/asp:ListItem&gt;
  &lt;/asp:CheckBoxList&gt;
  </code></pre>
  
  <p>This is nested inside the "ManageTemplatesPanel". I have created a <code>SelectedIndexChanged</code> event handler named <code>IncludeCheckBoxList_SelectedIndexChanged</code>. Here is the code:</p>
  
  <pre><code>protected void IncludeCheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
  {
      ListItemCollection items = IncludeCheckBoxList.Items;
      foreach (ListItem item in items)
      {
          string section = item.Value;
          bool itemChecked = item.Selected;
  
          if (0 == String.Compare(section, "Sent Client List", true))
              UpdateSentClientSection(itemChecked);
          else if (0 == String.Compare(section, "Notification Time", true))
              UpdateNotificationTimeSection(itemChecked);
          else if (0 == String.Compare(section, "Message", true))
              UpdateMessageSection(itemChecked);
      }
  }
  </code></pre>
  
  <p>Here is the code for <code>UpdateSentClientSection</code>:</p>
  
  <pre><code>private void UpdateSentClientSection(bool itemChecked)
  {
      if (itemChecked)
          MessageWhiteInsetPanel.BackColor = System.Drawing.Color.White;
      else
          MessageWhiteInsetPanel.BackColor = System.Drawing.Color.Blue;
  }
  </code></pre>
  
  <p>I've searched and several blogs recommend changing the backcolor of a panel in this fashion - but I can't get it to work. Any ideas why?</p>
  
  <p>Thanks in advance...</p>