This documentation is archived and is not being maintained.

HtmlTextWriter.IsAttributeDefined Method

Determines whether an HTML attribute is to be rendered in the next call to the RenderBeginTag method.

Overload List

Determines whether the specified HTML attribute is rendered during the next call to the RenderBeginTag method.

[Visual Basic] Overloads Protected Function IsAttributeDefined(HtmlTextWriterAttribute) As Boolean
[C#] protected bool IsAttributeDefined(HtmlTextWriterAttribute);
[C++] protected: bool IsAttributeDefined(HtmlTextWriterAttribute);
[JScript] protected function IsAttributeDefined(HtmlTextWriterAttribute) : Boolean;

Determines whether the specified HTML attribute and its value are rendered during the next call to the RenderBeginTag method.

[Visual Basic] Overloads Protected Function IsAttributeDefined(HtmlTextWriterAttribute, ByRef String) As Boolean
[C#] protected bool IsAttributeDefined(HtmlTextWriterAttribute, string);
[C++] protected: bool IsAttributeDefined(HtmlTextWriterAttribute, String);
[JScript] protected function IsAttributeDefined(HtmlTextWriterAttribute, String) : Boolean;

Example

[Visual Basic, C#, C++] The following example shows a custom HtmlTextWriter class that overrides the RenderBeginTag method. The code determines whether the HTML element to render is a < font > element or a < label > element. If it is a < font > element, the code uses the IsAttributeDefined method to determine whether a size attribute is defined for the element. If not, an AddAttribute method call is made that adds a size attribute and sets its value to 15 points.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of IsAttributeDefined. For other examples that might be available, see the individual overload topics.
[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 Language Filter in the upper-left corner of the page.

See Also

HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace

Show: