Export (0) Print
Expand All

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
)

Parameters

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.

Property

Initial Value

TagKey

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.

NoteNote

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" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">


    void Button1_Click(Object sender, EventArgs e) 
    {
        WebControl wc = new WebControl(HtmlTextWriterTag.Textarea);
        PlaceHolder1.Controls.Add(wc);
    }

</script>


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

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

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

    </div>
    </form>
</body>
</html>


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

Community Additions

ADD
Show:
© 2014 Microsoft