HtmlTextWriter.RenderBeforeTag HtmlTextWriter.RenderBeforeTag HtmlTextWriter.RenderBeforeTag HtmlTextWriter.RenderBeforeTag Method

定義

寫入標記項目的開頭標記之前所發生的任何文字或間距。Writes any text or spacing that occurs before the opening tag of a markup element.

protected:
 virtual System::String ^ RenderBeforeTag();
protected virtual string RenderBeforeTag ();
abstract member RenderBeforeTag : unit -> string
override this.RenderBeforeTag : unit -> string
Protected Overridable Function RenderBeforeTag () As String

傳回

要在標記項目的開頭標記之前寫入的文字或間距。The text or spacing to write before the markup element opening tag. 如果未覆寫,則為 nullIf not overridden, null.

範例

下列程式碼範例示範如何覆寫RenderBeforeTag方法,以判斷衍生HtmlTextWriter自類別的類別是否即將呈現<label>專案。The following code example shows how to override the RenderBeforeTag method to determine whether a class that is derived from the HtmlTextWriter class is about to render a <label> element. 若是如此, RenderBeforeTag覆寫就會將<font>元素的開頭標記插入緊接在<label>專案之前。If so, the RenderBeforeTag override inserts the opening tag of a <font> element immediately before the <label> element. 如果未轉譯RenderBeforeTag 元素,則會使用<label>基底方法。If it is not rendering a <label> element, the RenderBeforeTag base method is used.

// Override the RenderBeforeTag method to add the
// opening tag of a Font element before the
// opening tag of any Label elements rendered by this
// custom markup writer.
virtual String^ RenderBeforeTag() override
{
   // Compare the TagName property value to the
   // String* label to determine whether the element to
   // be rendered is a Label. If it is a Label,
   // the opening tag of the Font element, with a Color
   // style attribute set to red, is added before
   // the Label.
   if ( String::Compare( TagName, "label" ) == 0 )
   {
      return "<font color=\"red\">";
   }
   // If a Label is not being rendered, use
   // the base RenderBeforeTag method.
   else
   {
      return __super::RenderBeforeTag();
   }
}
// Override the RenderBeforeTag method to add the 
// opening tag of a Font element before the 
// opening tag of any Label elements rendered by this 
// custom markup writer. 
protected override string RenderBeforeTag()
{
    // Compare the TagName property value to the
    // string label to determine whether the element to 
    // be rendered is a Label. If it is a Label,
    // the opening tag of the Font element, with a Color
    // style attribute set to red, is added before
    // the Label.
    if (String.Compare(TagName, "label") == 0)
    {
        return "<font color=\"red\">";
    }
    // If a Label is not being rendered, use 
        // the base RenderBeforeTag method.
    else
    {
        return base.RenderBeforeTag();
    }
}
' Override the RenderBeforeTag method to add the 
' opening tag of a Font element before the 
' opening tag of any Label elements rendered by this 
' custom markup writer. 
Protected Overrides Function RenderBeforeTag() As String
    ' Compare the TagName property value to the
    ' string label to determine whether the element to 
    ' be rendered is a Label. If it is a Label,
    ' the opening tag of the Font element, with a Color
    ' style attribute set to red, is added before
    ' the Label.
    If String.Compare(TagName, "label") = 0 Then
        Return "<font color=""red"">"
        ' If a Label is not being rendered, use 
        ' the base RenderBeforeTag method.
    Else
        Return MyBase.RenderBeforeTag()
    End If
End Function 'RenderBeforeTag

備註

如果您想要在預定專案的開頭標記之前呈現其他開頭標記,方法會很有用。RenderBeforeTagThe RenderBeforeTag method can be useful if you want to render additional opening tags before the opening tag of the intended element.

給繼承者的注意事項

RenderBeforeTag() 方法nullHtmlTextWriter類別實會傳回。The HtmlTextWriter class implementation of the RenderBeforeTag() method returns null. 如果RenderBeforeTag()您想要在專案開頭標記之前寫入文字或間距,請覆寫。Override RenderBeforeTag() if you want to write text or spacing ahead of the element opening tag.

適用於

另請參閱