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
Available since 1.1
Return to top