HtmlTextWriter.RenderBeginTag 方法

定義

將標記項目的開頭標記寫入輸出資料流中。Writes the opening tag of a markup element to the output stream.

多載

RenderBeginTag(String)

將指定標記項目的開頭標記寫入到輸出資料流。Writes the opening tag of the specified markup element to the output stream.

RenderBeginTag(HtmlTextWriterTag)

將與指定的 HtmlTextWriterTag 列舉值相關聯的標記項目的開頭標記寫入輸出資料流中。Writes the opening tag of the markup element associated with the specified HtmlTextWriterTag enumeration value to the output stream.

RenderBeginTag(String)

將指定標記項目的開頭標記寫入到輸出資料流。Writes the opening tag of the specified markup element to the output stream.

public:
 virtual void RenderBeginTag(System::String ^ tagName);
public virtual void RenderBeginTag (string tagName);
abstract member RenderBeginTag : string -> unit
override this.RenderBeginTag : string -> unit
Public Overridable Sub RenderBeginTag (tagName As String)

參數

tagName
String

字串,包含要轉譯開頭標記之標記項目的名稱。A string containing the name of the markup element for which to render the opening tag.

範例

下列程式碼範例示範如何呼叫 RenderBeginTag 自訂控制項中的方法,以轉譯非標準元素的開頭標記 MyTagThe following code example shows how to call the RenderBeginTag method in a custom control to render the opening tag of a non-standard MyTag element. 然後,程式碼範例會呼叫 Write 方法來轉譯內部標記,然後呼叫 RenderEndTag 方法以關閉專案。The code example then calls the Write method to render inner markup, and then calls the RenderEndTag method to close the element.

這個程式碼範例會產生下列標記:This code example generates the following markup:

<MyTag>

Contents of MyTag

</MyTag>

// Create a non-standard tag.
writer->RenderBeginTag( "MyTag" );
writer->Write( "Contents of MyTag" );
writer->RenderEndTag();
writer->WriteLine();
// Create a non-standard tag.
writer.RenderBeginTag("MyTag");
writer.Write("Contents of MyTag");
writer.RenderEndTag();
writer.WriteLine();
' Create a non-standard tag.
writer.RenderBeginTag("MyTag")
writer.Write("Contents of MyTag")
writer.RenderEndTag()
writer.WriteLine()

備註

RenderBeginTag RenderBeginTag(String) 如果標記元素不是其中一個列舉值,請使用方法的覆寫 HtmlTextWriterTagUse the RenderBeginTag override of the RenderBeginTag(String) method, if the markup element is not one of the HtmlTextWriterTag enumeration values.

若要使用方法產生標記專案 RenderBeginTag ,請先 AddAttribute AddStyleAttribute 視需要呼叫和方法,以指定要出現在元素開頭標記中的任何專案屬性或樣式屬性。To generate a markup element by using the RenderBeginTag method, first call the AddAttribute and the AddStyleAttribute methods, as necessary, to specify any element attributes or style attributes that are to appear in the opening tag of the element. 產生內部標記之後,請呼叫 RenderEndTag 方法來產生結束記號。After generating the inner markup, call the RenderEndTag method to generate the closing tag.

另請參閱

適用於

RenderBeginTag(HtmlTextWriterTag)

將與指定的 HtmlTextWriterTag 列舉值相關聯的標記項目的開頭標記寫入輸出資料流中。Writes the opening tag of the markup element associated with the specified HtmlTextWriterTag enumeration value to the output stream.

public:
 virtual void RenderBeginTag(System::Web::UI::HtmlTextWriterTag tagKey);
public virtual void RenderBeginTag (System.Web.UI.HtmlTextWriterTag tagKey);
abstract member RenderBeginTag : System.Web.UI.HtmlTextWriterTag -> unit
override this.RenderBeginTag : System.Web.UI.HtmlTextWriterTag -> unit
Public Overridable Sub RenderBeginTag (tagKey As HtmlTextWriterTag)

參數

tagKey
HtmlTextWriterTag

其中一個 HtmlTextWriterTag 值,定義要呈現的標記項目的開頭標記。One of the HtmlTextWriterTag values that defines the opening tag of the markup element to render.

範例

下列程式碼範例示範如何使用 RenderBeginTag 方法來輸出元素的開頭標記 <img>The following code example shows how to use the RenderBeginTag method to output the opening tag of an <img> element. 方法加入至專案的屬性 AddAttribute 將會在開頭 <img> 標記中。The attributes that are added to the element by the AddAttribute method will be in the opening <img> tag. RenderEndTag方法用來產生結束記號。The RenderEndTag method is used to generate the closing tag.

這個程式碼範例會產生下列標記:This code example generates the following markup:

<img alt="Encoding &quot;Required&quot;" myattribute="No &quot;encoding&quot; required">

</img>

// Control the encoding of attributes.
// Simple known values do not need encoding.
writer->AddAttribute( HtmlTextWriterAttribute::Alt, "Encoding, \"Required\"", true );
writer->AddAttribute( "myattribute", "No &quot;encoding &quot; required", false );
writer->RenderBeginTag( HtmlTextWriterTag::Img );
writer->RenderEndTag();
writer->WriteLine();
// Control the encoding of attributes. 
// Simple known values do not need encoding.
writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, \"Required\"", true);
writer.AddAttribute("myattribute", "No &quot;encoding &quot; required", false);
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
writer.WriteLine();
' Control the encoding of attributes.
' Simple known values do not need encoding.
writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Encoding, ""Required""", True)
writer.AddAttribute("myattribute", "No &quot;encoding &quot; required", False)
writer.RenderBeginTag(HtmlTextWriterTag.Img)
writer.RenderEndTag()
writer.WriteLine()

備註

RenderBeginTag RenderBeginTag(HtmlTextWriterTag) 如果標記專案是已知型別(也就是其中一個列舉值),請使用方法的多載 HtmlTextWriterTagUse the RenderBeginTag overload of the RenderBeginTag(HtmlTextWriterTag) method if the markup element is of a known type that is one of the HtmlTextWriterTag enumeration values.

若要使用方法產生標記專案 RenderBeginTag ,請先 AddAttribute AddStyleAttribute 視需要呼叫和方法,以指定要出現在元素開頭標記中的任何專案屬性或樣式屬性。To generate a markup element by using the RenderBeginTag method, first call the AddAttribute and the AddStyleAttribute methods, as necessary, to specify any element attributes or style attributes that are to appear in the opening tag of the element. 產生內部標記之後,請呼叫 RenderEndTag 方法來產生結束記號。After generating the inner markup, call the RenderEndTag method to generate the closing tag.

另請參閱

適用於