System.Web.UI.HtmlControls HtmlControl Class
Sets or retrieves inline style information for the HTML control.
Inline |
<htmlcontrol Style = strStyle ... > |
Script |
HtmlControl.Style [ = strStyle ] |
strStyle |
String specifying the declaration block syntax for the inline stylesheet. |
Returns a System.Web.UI.CssStyleCollection that represents the HTML style attribute that is rendered within the opening tag of the HTML control.
This property is read/write with no default value.
Style is used to set or get the collection of Cascading Style Sheets ( CSS ) attributes that is applied as an HTML style attribute on an HtmlControl at run time. The syntax for the HTML style attribute is determined by the CSS standard.
NOTE: For reference, see the Cascading Style Sheets, Level 2 Specification for the complete list, description, and sample usage of style declaration syntax.
This property can be applied to almost all controls.
The following example shows how to declaratively set the Style property of an HtmlControl at design time.
<div runat="server" style="font: bold 12pt arial; background-color: khaki">
The example below shows how to programmatically set the Style property at run time, depending on user input.
void applyStyle ( object src, EventArgs e ) {
switch ( myStyle.SelectedIndex ) {
case 0:
greeting.Style [ "font" ] ="bold italic 13pt verdana";
break;
case 1:
greeting.Style [ "color" ] ="maroon";
break;
case 2:
greeting.Style [ "background-color" ] ="khaki";
break;
case 3:
greeting.Style [ "border" ] ="1px silver inset";
break;
}
}
Show me
HtmlControl Members System.Web.UI.CssStyleCollection