Upravit

Sdílet prostřednictvím


HtmlTextWriter.RenderBeginTag Method

Definition

Writes the opening tag of a markup element to the output stream.

Overloads

RenderBeginTag(String)

Writes the opening tag of the specified markup element to the output stream.

RenderBeginTag(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)

Parameters

tagName
String

A string containing the name of the markup element for which to render the opening tag.

Examples

The 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. 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()

Remarks

Use the RenderBeginTag override of the RenderBeginTag(String) method, if the markup element is not one of the HtmlTextWriterTag enumeration values.

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. After generating the inner markup, call the RenderEndTag method to generate the closing tag.

See also

Applies to

RenderBeginTag(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)

Parameters

tagKey
HtmlTextWriterTag

One of the HtmlTextWriterTag values that defines the opening tag of the markup element to render.

Examples

The following code example shows how to use the RenderBeginTag method to output the opening tag of an <img> element. The attributes that are added to the element by the AddAttribute method will be in the opening <img> tag. 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 "encoding " 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 "encoding " 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 "encoding " required", False)
writer.RenderBeginTag(HtmlTextWriterTag.Img)
writer.RenderEndTag()
writer.WriteLine()

Remarks

Use 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.

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. After generating the inner markup, call the RenderEndTag method to generate the closing tag.

See also

Applies to