This documentation is archived and is not being maintained.

WebControl Constructor (HtmlTextWriterTag)

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 Page Code Model.

Security noteSecurity 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="" >
<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

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.