Редагувати

Поділитися через


AttributeCollection.CssStyle Property

Definition

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

public:
 property System::Web::UI::CssStyleCollection ^ CssStyle { System::Web::UI::CssStyleCollection ^ get(); };
public System.Web.UI.CssStyleCollection CssStyle { get; }
member this.CssStyle : System.Web.UI.CssStyleCollection
Public ReadOnly Property CssStyle As CssStyleCollection

Property Value

A collection that contains the styles for the current server control.

Examples

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.
   myAttributes.CssStyle.Add("background-color",myColor);
   
}
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

Remarks

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.

Applies to

See also