HtmlTextWriter.GetAttributeKey Method
Obtains the corresponding HtmlTextWriterAttribute enumeration value for the specified HTML attribute.
[Visual Basic] Protected Function GetAttributeKey( _ ByVal attrName As String _ ) As HtmlTextWriterAttribute [C#] protected HtmlTextWriterAttribute GetAttributeKey( string attrName ); [C++] protected: HtmlTextWriterAttribute GetAttributeKey( String* attrName ); [JScript] protected function GetAttributeKey( attrName : String ) : HtmlTextWriterAttribute;
Parameters
- attrName
- The HTML attribute to obtain the HtmlTextWriterAttribute value for.
Return Value
The HtmlTextWriterAttribute enumeration value for the specified HTML attribute, or unkown if the attribute is not a member of the enumeration.
Example
[Visual Basic, C#, C++] The following example shows a custom HtmlTextWriter class that overrides the RenderBeginTag method. In the overridden method, the code checks whether the tagKey parameter is equal to Font, which indicates that an HTML < font > element is to be rendered. If so, the code calls the IsStyleAttributeDefined method to find out whether the < font > element contains a size attribute. If IsStyleAttributeDefined returns false, an AddAttribute method call in turn calls the GetAttributeKey method. The GetAttributeKey call defines the size attribute and sets its value to 30 point.
[Visual Basic] ' If the tagKey parameter is set to a font element ' but a size attribute is not defined on the element, ' the AddStyleAttribute method call adds a size attribute ' and sets it to 30-point. If tagKey = HtmlTextWriterTag.Font Then If Not IsAttributeDefined(HtmlTextWriterAttribute.Size) Then AddAttribute(GetAttributeKey("size"), "30pt") End If End If [C#] // If the tagKey parameter is set to a font element // but a size attribute is not defined on the element, // the AddStyleAttribute method call adds a size attribute // and sets it to 30-point. if(tagKey == HtmlTextWriterTag.Font) { if(!IsAttributeDefined(HtmlTextWriterAttribute.Size)) { AddAttribute(GetAttributeKey("size"), "30pt"); } } [C++] // If the tagKey parameter is set to a font element // but a size attribute is not defined on the element, // the AddStyleAttribute method call adds a size attribute // and sets it to 30-point. if (tagKey == HtmlTextWriterTag::Font) { if (!IsAttributeDefined(HtmlTextWriterAttribute::Size)) { AddAttribute(GetAttributeKey(S"size"), S"30pt"); } }
[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