Export (0) Print
Expand All

WebControl.BackColor Property

Gets or sets the background color of the Web server control.

[Visual Basic]
Public Overridable Property BackColor As Color
[C#]
public virtual Color BackColor {get; set;}
[C++]
public: __property virtual Color get_BackColor();
public: __property virtual void set_BackColor(Color);
[JScript]
public function get BackColor() : Color;
public function set BackColor(Color);

Property Value

A System.Drawing.Color that represents the background color of the control. The default is Color.Empty, which indicates that this property is not set.

Remarks

Use the BackColor property to specify the background color of the Web server control. This property is set using a System.Drawing.Color object.

Note   This property will render for only certain controls. For example, Table, Panel, DataGrid, Calendar, and ValidationSummary will render this property. It will also work for CheckBoxList, RadioButtonList and DataList if their RepeatLayout property is RepeatLayout.Table, not RepeatLayout.Flow.

In general, only controls that render as a <table> tag can display a background color in HTML 3.2, whereas almost any control can in HTML 4.0.

For controls that render as a <span> tag (including Label, all validation controls, and list controls with their RepeatLayout property set to RepeatLayout.Flow), this property will work in Microsoft Internet Explorer version 5 and later, but not in Microsoft Internet Explorer version 4.

Example

[Visual Basic, C#, JScript] The following example illustrates how to set the BackColor property of the Table control, which is inherited from the WebControl base class.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
 <body>
     <h3>BackColor Property of a Web Control</h3>
 
 <form runat=server>
 
 <asp:Table id="Table1" runat="server"
    CellPadding=10 
    GridLines="Both"
 
    BackColor="LightGreen"
 >
 
    <asp:TableRow>
       <asp:TableCell>
          Row 0, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 0, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
    <asp:TableRow>
       <asp:TableCell>
          Row 1, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 1, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
 </asp:Table>
 
 </form>
 
 </body>
 </html>
 

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <body>
     <h3>BackColor Property of a Web Control</h3>
 
 <form runat=server>
 
 <asp:Table id="Table1" runat="server"
    CellPadding=10 
    GridLines="Both"
 
    BackColor="LightGreen"
 >
 
    <asp:TableRow>
       <asp:TableCell>
          Row 0, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 0, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
    <asp:TableRow>
       <asp:TableCell>
          Row 1, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 1, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
 </asp:Table>
 
 </form>
 
 </body>
 </html>
 

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
 <body>
     <h3>BackColor Property of a Web Control</h3>
 
 <form runat=server>
 
 <asp:Table id="Table1" runat="server"
    CellPadding=10 
    GridLines="Both"
    BackColor="LightGreen"
 >
 
    <asp:TableRow>
       <asp:TableCell>
          Row 0, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 0, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
    <asp:TableRow>
       <asp:TableCell>
          Row 1, Col 0
       </asp:TableCell>
 
       <asp:TableCell>
          Row 1, Col 1
       </asp:TableCell>
    </asp:TableRow>
 
 </asp:Table>
 
 </form>
 
 </body>
 </html>
 

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace | System.Drawing.Color | Style | Table | Panel | DataGrid | Calendar | ValidationSummary | CheckBoxList | RadioButtonList | DataList | RepeatLayout

Show:
© 2014 Microsoft