This documentation is archived and is not being maintained.

HtmlTextWriter.RenderBeginTag Method (HtmlTextWriterTag)

Writes the opening tag of the markup element associated with the specified HtmlTextWriterTag enumeration value to the output stream.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public virtual void RenderBeginTag(
	HtmlTextWriterTag tagKey


Type: System.Web.UI.HtmlTextWriterTag
One of the HtmlTextWriterTag values that defines the opening tag of the markup element to render.

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.

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">


// 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);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.