แก้ไข

แชร์ผ่าน


WebControl Constructors

Definition

Initializes a new instance of the WebControl class.

Overloads

WebControl()

Initializes a new instance of the WebControl class that represents a Span HTML tag.

WebControl(String)

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

WebControl(HtmlTextWriterTag)

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

WebControl()

Initializes a new instance of the WebControl class that represents a Span HTML tag.

protected:
 WebControl();
protected WebControl ();
Protected Sub New ()

Remarks

This constructor is used to initialize a new instance of the WebControl class that represents a Span HTML element.

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

Property Initial Value
TagKey The Span enumeration value.

Note

This constructor is not called directly. Instead, it is often called by the constructor of a derived class to initialize the TagKey property to the Span enumeration value.

See also

Applies to

WebControl(String)

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

protected:
 WebControl(System::String ^ tag);
protected WebControl (string tag);
new System.Web.UI.WebControls.WebControl : string -> System.Web.UI.WebControls.WebControl
Protected Sub New (tag As String)

Parameters

tag
String

An HTML tag.

Remarks

Use this constructor to create and initialize a new instance of the WebControl class using the specified HTML tag.

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

Property Initial Value
TagKey The Unknown enumeration value.
TagName The value of the tag parameter.

Note

This constructor is not called directly. Instead, it is often called by the constructor of a derived class to initialize the TagKey and TagName properties.

See also

Applies to

WebControl(HtmlTextWriterTag)

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

public:
 WebControl(System::Web::UI::HtmlTextWriterTag tag);
public WebControl (System.Web.UI.HtmlTextWriterTag tag);
new System.Web.UI.WebControls.WebControl : System.Web.UI.HtmlTextWriterTag -> System.Web.UI.WebControls.WebControl
Public Sub New (tag As HtmlTextWriterTag)

Parameters

tag
HtmlTextWriterTag

One of the HtmlTextWriterTag values.

Examples

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.

Note

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.

Important

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>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs) 
        Dim wc As New WebControl(HtmlTextWriterTag.Textarea)
        PlaceHolder1.Controls.Add(wc)
    End Sub

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

Remarks

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.

See also

Applies to