Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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
)
public void RenderBeginTag (
	HtmlTextWriterTag tagKey
)
public function RenderBeginTag (
	tagKey : HtmlTextWriterTag
)
Not applicable.

Parameters

tagKey

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

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft