HtmlTextWriter.WriteBeginTag(String) 方法

定义

将任何制表符间距和指定标记元素的开始标记写入到输出流。Writes any tab spacing and the opening tag of the specified markup element to the output stream.

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

参数

tagName
String

要写入其开始标记的标记元素。The markup element of which to write the opening tag.

示例

下面的代码示例演示如何呈现<img>一个元素,在该元素中WriteAttribute调用方法的两个重载。The following code example demonstrates rendering an <img> element in which both overloads of the WriteAttribute method are called. 此代码示例使用以下过程:The code example uses the following process:

此代码示例生成以下标记:This code example generates the following markup:

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

</img>

// Create a manually rendered tag.
writer->WriteBeginTag( "img" );
writer->WriteAttribute( "alt", "AtlValue" );
writer->WriteAttribute( "myattribute", "No &quot;encoding &quot; required", false );
writer->Write( HtmlTextWriter::TagRightChar );
writer->WriteEndTag( "img" );
// Create a manually rendered tag.
writer.WriteBeginTag("img");
writer.WriteAttribute("alt", "AtlValue");
writer.WriteAttribute("myattribute", "No &quot;encoding &quot; required", false);
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("img");
' Create a manually rendered tag.
writer.WriteBeginTag("img")
writer.WriteAttribute("alt", "AtlValue")
writer.WriteAttribute("myattribute", "No &quot;encoding &quot; required", False)
writer.Write(HtmlTextWriter.TagRightChar)

注解

WriteBeginTag方法不会写入标记元素的开始标记的右尖括号(>)。The WriteBeginTag method does not write the closing angle bracket (>) of the markup element's opening tag. 这允许将标记特性写入元素的开始标记中。This allows the writing of markup attributes to the opening tag of the element. 调用方法时,使用TagRightChar常量关闭WriteBeginTag开始标记。Use the TagRightChar constant to close the opening tag when calling the WriteBeginTag method. 编写自结束标记元素SelfClosingTagEnd时,请将方法与常量结合使用。WriteBeginTagUse the WriteBeginTag method with the SelfClosingTagEnd constant when you write markup elements that are self-closing.

自定义服务器控件使用方法,这些控件不允许标记或属性映射,并以相同的方式为每个请求呈现标记元素。WriteBeginTagThe WriteBeginTag method is used by custom server controls that do not allow tag or attribute mapping and render markup elements in the same way for each request.

适用于

另请参阅