This documentation is archived and is not being maintained.
HtmlTextWriter.GetStyleName Method
.NET Framework 1.1
Obtains the HTML style attribute associated with the specified HtmlTextWriterStyle enumeration value.
[Visual Basic] Protected Function GetStyleName( _ ByVal styleKey As HtmlTextWriterStyle _ ) As String [C#] protected string GetStyleName( HtmlTextWriterStyle styleKey ); [C++] protected: String* GetStyleName( HtmlTextWriterStyle styleKey ); [JScript] protected function GetStyleName( styleKey : HtmlTextWriterStyle ) : String;
Parameters
- styleKey
- The HtmlTextWriterStyle value to obtain the HTML style attribute for.
Return Value
The HTML style attribute.
Example
[Visual Basic] ' If the HTML element being rendered is a <Label>, ' render the opening tag of a Font element before it. If tagKey = HtmlTextWriterTag.Label Then ' Check whether a Color style attribute is ' included on the Label. If not, use the ' AddStyleAttribute and GetStyleName methods to add one ' and set its value to red. If Not IsStyleAttributeDefined(HtmlTextWriterStyle.Color) Then AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red") End If [C#] // If the HTML element being rendered is a <Label>, // render the opening tag of a <Font> element before it. if(tagKey == HtmlTextWriterTag.Label) { // Check whether a Color style attribute is // included on the Label. If not, use the // AddStyleAttribute and GetStyleName methods to add one // and set its value to red. if(!IsStyleAttributeDefined(HtmlTextWriterStyle.Color)) { AddStyleAttribute(GetStyleName(HtmlTextWriterStyle.Color), "red"); } [C++] // If the HTML element being rendered is a <Label>, // render the opening tag of a <Font> element before it. if (tagKey == HtmlTextWriterTag::Label) { // Check whether a Color style attribute is // included on the Label. If not, use the // AddStyleAttribute and GetStyleName methods to add one // and set its value to red. if (!IsStyleAttributeDefined(HtmlTextWriterStyle::Color)) { AddStyleAttribute(GetStyleName(HtmlTextWriterStyle::Color), S"red"); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace
Show: