Export (0) Print
Expand All

HtmlTextWriter.WriteBeginTag Method

Writes any tab spacing and the opening tag of the specified markup element to the output stream.

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

public virtual void WriteBeginTag (
	string tagName
)
public void WriteBeginTag (
	String tagName
)
public function WriteBeginTag (
	tagName : String
)
Not applicable.

Parameters

tagName

The markup element of which to write the opening tag.

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. Use the TagRightChar constant to close the opening tag when calling the WriteBeginTag method. Use the WriteBeginTag method with the SelfClosingTagEnd constant when you write markup elements that are self-closing.

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

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:

  • Calls the WriteBeginTag method, which renders the opening characters of the element.

  • Calls the WriteAttribute(String,String) overload, which writes an alt attribute and its value to the <img> element.

  • Calls the WriteAttribute(String,String,Boolean) overload to render a custom myattribute attribute, with a value of No "encoding" required, and then sets fEncode to false.

  • Closes the opening tag of the element, and then calls the WriteEndTag method to close the <img> element.

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

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