AttributeCollection.CssStyle Property
.NET Framework (current version)
Gets a collection of styles for the ASP.NET server control to which the current AttributeCollection object belongs.
Assembly: System.Web (in System.Web.dll)
Property Value
Type: System.Web.UI.CssStyleCollectionA 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 Sub Button2_Click(sender As Object, e As System.EventArgs) Dim myColor As String Dim myAttributes As AttributeCollection = TextBox1.Attributes myColor = DropDownList1.Items(DropDownList1.SelectedIndex).Text ' Add the attribute "background-color" in to the CssStyle. myAttributes.CssStyle.Add("background-color", myColor) End Sub
.NET Framework
Available since 1.1
Available since 1.1
Show: