HtmlTextWriter.RenderBeforeContent HtmlTextWriter.RenderBeforeContent HtmlTextWriter.RenderBeforeContent HtmlTextWriter.RenderBeforeContent Method

定義

在標記項目的內容之前及開頭標記之後寫入任何文字或間距。Writes any text or spacing before the content and after the opening tag of a markup element.

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

傳回

要在項目的內容之前寫入的文字或間距。The text or spacing to write prior to the content of the element. 如果未覆寫,則 RenderBeforeContent() 會傳回 nullIf not overridden, RenderBeforeContent() returns null.

範例

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

// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.

virtual String^ RenderBeforeContent() override
{
   
   // Check to determine whether the element being rendered
   // is a label element. If so, render the opening tag
   // of the font element; otherwise, call the base method.
   if ( TagKey == HtmlTextWriterTag::Label )
   {
      return "<font color=\"red\">";
   }
   else
   {
      return __super::RenderBeforeContent();
   }
}


// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected override string RenderBeforeContent()
{
    // Check to determine whether the element being rendered
    // is a label element. If so, render the opening tag
    // of the font element; otherwise, call the base method.
    if (TagKey == HtmlTextWriterTag.Label)
    {
        return "<font color=\"red\">";
    }
    else
    {
        return base.RenderBeforeContent();
    }
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
    ' Check to determine whether the element being rendered
    ' is a label element. If so, render the opening tag
    ' of the font element; otherwise, call the base method.
    If TagKey = HtmlTextWriterTag.Label Then
        Return "<font color=""red"">"
    Else
        Return MyBase.RenderBeforeContent()
    End If
End Function 'RenderBeforeContent

備註

如果您想要在內部標記之前將子專案插入至目前的標記專案,方法會很有用。RenderBeforeContentThe RenderBeforeContent method can be useful if you want to insert child elements into the current markup element before the inner markup.

給繼承者的注意事項

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

適用於

另請參閱