WebControl Constructor (HtmlTextWriterTag)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the WebControl class using the specified HTML tag.

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

public WebControl(
	HtmlTextWriterTag tag


Type: System.Web.UI.HtmlTextWriterTag

One of the HtmlTextWriterTag values.

Use this constructor to create and initialize a new instance of the WebControl class using the specified System.Web.UI.HtmlTextWriterTag value.

The following table shows the initial property value for an instance of WebControl.


Initial Value


The HtmlTextWriterTag enumeration value specified by the tag parameter.

The following example demonstrates how to use the constructor for the WebControl class to create a TextArea HTML element and display it on the Web Forms page.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx file name extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

System_CAPS_security Security Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">

    void Button1_Click(Object sender, EventArgs e) 
        WebControl wc = new WebControl(HtmlTextWriterTag.Textarea);


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>WebControl Example</title>
    <form id="form1" runat="server">

    <h3>WebControl Constructor Example</h3>
        <asp:PlaceHolder id="PlaceHolder1"

        <asp:Button id="Button1" runat="Server"
            Text="Click to create a new TextArea" 
            OnClick="Button1_Click" />


.NET Framework
Available since 1.1
Return to top