Export (0) Print
Expand All

AttributeCollection.CssStyle Property

Gets a collection of styles for the ASP.NET server control to which the current AttributeCollection object belongs.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public CssStyleCollection CssStyle { get; }

Property Value

Type: System.Web.UI.CssStyleCollection
A collection that contains the styles for the current server control.

Any style declared for a particular HTML server control is added to the CssStyleCollection object when the containing ASP.NET Web page is parsed. You can use this property to add, remove, and iterate through the styles declared for the server control.

The following example shows how to add a CSS style value programmatically to a server control's AttributeCollection object. When a button is clicked, the background color of a TextBox server control named TextBox1 is set to the selected item in a DropDownList server control named DropDownList1.

private void Button2_Click(object sender, System.EventArgs e)

   string myColor;
   AttributeCollection myAttributes = TextBox1.Attributes;
   myColor = DropDownList1.Items[DropDownList1.SelectedIndex].Text;
   // Add the attribute "background-color" in to the CssStyle.


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft