HtmlTextWriter.OnTagRender(String, HtmlTextWriterTag) HtmlTextWriter.OnTagRender(String, HtmlTextWriterTag) HtmlTextWriter.OnTagRender(String, HtmlTextWriterTag) HtmlTextWriter.OnTagRender(String, HtmlTextWriterTag) Method

定義

判斷指定的標記項目是否將在提出要求的網頁上呈現。Determines whether the specified markup element will be rendered to the requesting page.

protected:
 virtual bool OnTagRender(System::String ^ name, System::Web::UI::HtmlTextWriterTag key);
protected virtual bool OnTagRender (string name, System.Web.UI.HtmlTextWriterTag key);
abstract member OnTagRender : string * System.Web.UI.HtmlTextWriterTag -> bool
override this.OnTagRender : string * System.Web.UI.HtmlTextWriterTag -> bool
Protected Overridable Function OnTagRender (name As String, key As HtmlTextWriterTag) As Boolean

參數

name
String String String String

字串,包含要呈現的項目名稱。A string containing the name of the element to render.

key
HtmlTextWriterTag HtmlTextWriterTag HtmlTextWriterTag HtmlTextWriterTag

與此項目相關聯的 HtmlTextWriterTagThe HtmlTextWriterTag associated with the element.

傳回

一定是 trueAlways true.

範例

下列程式碼範例顯示如何覆寫OnTagRender方法。The following code example shows how to override the OnTagRender method. 如果正在轉譯OnTagRender IsAttributeDefined Size元素,覆寫會使用方法來判斷是否正在呈現屬性。 FontIf a Font element is being rendered, the OnTagRender override uses the IsAttributeDefined method to determine whether a Size attribute is being rendered. 如果不是Size ,它會AddAttribute使用方法來建立屬性,並將其值20pt設定為。If not, it uses the AddAttribute method to create a Size attribute and set its value to 20pt.

// If a <font> element is to be rendered, check whether it contains
// a size attribute. If it does not, add one and set its value to
// 20 points, then return true.
protected override bool OnTagRender(string name, HtmlTextWriterTag key)
{

    if (key == HtmlTextWriterTag.Font)
    {
        if (!(IsAttributeDefined(HtmlTextWriterAttribute.Size)))
        {
            AddAttribute(HtmlTextWriterAttribute.Size, "20pt");
            return true;
        }
    }

    // If the element is not a <font> element, use
    // the base functionality of the OnTagRenderMethod.
    return base.OnTagRender(name, key);
}
' If a <font> element is to be rendered, check whether it contains
' a size attribute. If it does not, add one and set its value to
' 20 points, then return true.
Protected Overrides Function OnTagRender( _
    name As String, _
    key As HtmlTextWriterTag) _
As Boolean

    If (key = HtmlTextWriterTag.Font) Then
        If Not (IsAttributeDefined(HtmlTextWriterAttribute.Size)) Then
            AddAttribute(HtmlTextWriterAttribute.Size, "20pt")
            Return True
        End If
    End If

    ' If the element is not a <font> element, use
    ' the base functionality of the OnTagRenderMethod.
    Return MyBase.OnTagRender(name, key)
End Function

備註

方法的類別實HtmlTextWriter true作為一律會傳回。 OnTagRenderThe HtmlTextWriter class implementation of the OnTagRender method always returns true. OnTagRender覆寫可以決定是否要將專案轉譯至頁面。The OnTagRender overrides can determine whether an element will be rendered to the page.

給繼承者的注意事項

如果您繼承自HtmlTextWriter類別,您可以覆OnTagRender(String, HtmlTextWriterTag)寫方法以false傳回,以防止標記專案完全轉譯或特定標記語言的呈現。If you inherit from the HtmlTextWriter class, you can override the OnTagRender(String, HtmlTextWriterTag) method to return false to prevent a markup element from being rendered at all or for a particular markup language. 例如,如果您不希望HtmlTextWriter衍生自<font>的物件轉譯元素OnTagRender(String, HtmlTextWriterTag) ,您可以覆false寫方法,以在要求包含<font>專案的頁面時傳回。For example, if you do not want the object that is derived from HtmlTextWriter to render the <font> element, you can override the OnTagRender(String, HtmlTextWriterTag) method to return false when a page is requested that contains a <font> element.

適用於

另請參閱