Export (0) Print
Expand All
0 out of 4 rated this helpful - Rate this topic

WebControl.BackColor Property

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

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual Color BackColor { get; set; }
/** @property */
public Color get_BackColor ()

/** @property */
public void set_BackColor (Color value)

public function get BackColor () : Color

public function set BackColor (value : Color)

Property Value

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

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

NoteNote

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.

The following example illustrates how to set the BackColor property of the Table control, which is inherited from the WebControl base class.

<%@ 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>
 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.