HtmlTextWriter.IsAttributeDefined 方法

定义

确定是否在下一次调用 RenderBeginTag 方法时呈现指定的标记属性及其值。Determines whether the specified markup attribute and its value are rendered during the next call to the RenderBeginTag method.

重载

IsAttributeDefined(HtmlTextWriterAttribute)

确定是否在下一次调用 RenderBeginTag 方法时呈现指定的标记属性及其值。Determines whether the specified markup attribute and its value are rendered during the next call to the RenderBeginTag method.

IsAttributeDefined(HtmlTextWriterAttribute, String)

确定是否在下一次调用 RenderBeginTag 方法时呈现指定的标记属性及其值。Determines whether the specified markup attribute and its value are rendered during the next call to the RenderBeginTag method.

IsAttributeDefined(HtmlTextWriterAttribute)

确定是否在下一次调用 RenderBeginTag 方法时呈现指定的标记属性及其值。Determines whether the specified markup attribute and its value are rendered during the next call to the RenderBeginTag method.

protected:
 bool IsAttributeDefined(System::Web::UI::HtmlTextWriterAttribute key);
protected bool IsAttributeDefined (System.Web.UI.HtmlTextWriterAttribute key);
member this.IsAttributeDefined : System.Web.UI.HtmlTextWriterAttribute -> bool
Protected Function IsAttributeDefined (key As HtmlTextWriterAttribute) As Boolean

参数

key
HtmlTextWriterAttribute

与标记属性关联的 HtmlTextWriterAttributeThe HtmlTextWriterAttribute associated with the markup attribute.

返回

如果下次调用 RenderBeginTag 方法时呈现该属性,则为 true;否则为 falsetrue if the attribute is rendered during the next call to the RenderBeginTag method; otherwise, false.

示例

下面的代码示例演示如何在RenderBeginTag HtmlTextWriter从类继承的类中使用方法的重写。The following code example shows how to use an override of the RenderBeginTag method in a class that inherits from the HtmlTextWriter class. 重写检查<font>是否将呈现标记元素。 RenderBeginTagThe RenderBeginTag override checks whether a <font> markup element will be rendered. 如果是这样,则重写IsAttributeDefined会调用方法来检查<font>元素是否包含Size特性。If so, the override calls the IsAttributeDefined method to check whether the <font> element contains a Size attribute. 如果不是, AddAttribute则方法GetAttributeKey调用Size方法,该方法定义特性并将其值设置30pt为。If not, the AddAttribute method calls the GetAttributeKey method, which defines the Size attribute and sets its value to 30pt.

// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point.
if ( tagKey == HtmlTextWriterTag::Font )
{
   if (  !IsAttributeDefined( HtmlTextWriterAttribute::Size ) )
   {
      AddAttribute( GetAttributeKey( "size" ), "30pt" );
   }
}
// If the tagKey parameter is set to a <font> element
// but a size attribute is not defined on the element,
// the AddStyleAttribute method adds a size attribute
// and sets it to 30 point. 
if (tagKey == HtmlTextWriterTag.Font)
{
    if (!IsAttributeDefined(HtmlTextWriterAttribute.Size))
    {
        AddAttribute(GetAttributeKey("size"), "30pt");
    }
}
' If the tagKey parameter is set to a <font> element
' but a size attribute is not defined on the element,
' the AddStyleAttribute method 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

注解

若要获取要分配HtmlTextWriterAttribute给对象的值,请IsAttributeDefined(HtmlTextWriterAttribute, String)使用重载,而不是此重载。To obtain the value to be assigned to the HtmlTextWriterAttribute object, use the IsAttributeDefined(HtmlTextWriterAttribute, String) overload instead of this one.

另请参阅

IsAttributeDefined(HtmlTextWriterAttribute, String)

确定是否在下一次调用 RenderBeginTag 方法时呈现指定的标记属性及其值。Determines whether the specified markup attribute and its value are rendered during the next call to the RenderBeginTag method.

protected:
 bool IsAttributeDefined(System::Web::UI::HtmlTextWriterAttribute key, [Runtime::InteropServices::Out] System::String ^ % value);
protected bool IsAttributeDefined (System.Web.UI.HtmlTextWriterAttribute key, out string value);
member this.IsAttributeDefined : System.Web.UI.HtmlTextWriterAttribute * string -> bool
Protected Function IsAttributeDefined (key As HtmlTextWriterAttribute, ByRef value As String) As Boolean

参数

key
HtmlTextWriterAttribute

与标记属性关联的 HtmlTextWriterAttributeThe HtmlTextWriterAttribute associated with the markup attribute.

value
String

要分配给特性的值。The value assigned to the attribute.

返回

如果下次调用 RenderBeginTag 方法时呈现该属性,则为 true;否则为 falsetrue if the attribute is rendered during the next call to the RenderBeginTag method; otherwise, false.

注解

如果该IsAttributeDefined方法返回true,则在value参数中返回要赋HtmlTextWriterAttribute给对象的值。If the IsAttributeDefined method returns true, the value to be assigned to the HtmlTextWriterAttribute object is returned in the value parameter.

另请参阅

适用于