WebControl Construtores

Definição

Inicializa uma nova instância da classe WebControl.Initializes a new instance of the WebControl class.

Sobrecargas

WebControl()

Inicializa uma nova instância da classe WebControl que representa uma marca HTML Span.Initializes a new instance of the WebControl class that represents a Span HTML tag.

WebControl(String)

Inicializa uma nova instância da classe WebControl usando a marca HTML especificada.Initializes a new instance of the WebControl class using the specified HTML tag.

WebControl(HtmlTextWriterTag)

Inicializa uma nova instância da classe WebControl usando a marca HTML especificada.Initializes a new instance of the WebControl class using the specified HTML tag.

WebControl()

Inicializa uma nova instância da classe WebControl que representa uma marca HTML Span.Initializes a new instance of the WebControl class that represents a Span HTML tag.

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

Comentários

Esse construtor é usado para inicializar uma nova instância da WebControl classe que representa um Span elemento HTML.This constructor is used to initialize a new instance of the WebControl class that represents a Span HTML element.

A tabela a seguir mostra o valor da propriedade inicial para uma instância do WebControl .The following table shows the initial property value for an instance of WebControl.

PropriedadeProperty Valor inicialInitial Value
TagKey O valor de enumeração Span.The Span enumeration value.

Observação

Esse construtor não é chamado diretamente.This constructor is not called directly. Em vez disso, ele é frequentemente chamado pelo construtor de uma classe derivada para inicializar a TagKey propriedade para o Span valor de enumeração.Instead, it is often called by the constructor of a derived class to initialize the TagKey property to the Span enumeration value.

Confira também

Aplica-se a

WebControl(String)

Inicializa uma nova instância da classe WebControl usando a marca HTML especificada.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)

Parâmetros

tag
String

Uma marca HTML.An HTML tag.

Comentários

Use este construtor para criar e inicializar uma nova instância da WebControl classe usando a marca HTML especificada.Use this constructor to create and initialize a new instance of the WebControl class using the specified HTML tag.

A tabela a seguir mostra os valores de propriedade inicial para uma instância do WebControl .The following table shows initial property values for an instance of WebControl.

PropriedadeProperty Valor inicialInitial Value
TagKey O valor de enumeração Unknown.The Unknown enumeration value.
TagName O valor do tag parâmetro.The value of the tag parameter.

Observação

Esse construtor não é chamado diretamente.This constructor is not called directly. Em vez disso, ele é frequentemente chamado pelo construtor de uma classe derivada para inicializar TagKey as TagName Propriedades e.Instead, it is often called by the constructor of a derived class to initialize the TagKey and TagName properties.

Confira também

Aplica-se a

WebControl(HtmlTextWriterTag)

Inicializa uma nova instância da classe WebControl usando a marca HTML especificada.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)

Parâmetros

tag
HtmlTextWriterTag

Um dos valores de HtmlTextWriterTag.One of the HtmlTextWriterTag values.

Exemplos

O exemplo a seguir demonstra como usar o construtor para a WebControl classe para criar um TextArea elemento HTML e exibi-lo na página Web Forms.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.

Observação

O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão de nome de arquivo. aspx.This code sample must be copied into an empty text file that has an .aspx file name extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

Importante

Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example has a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.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>

Comentários

Use este construtor para criar e inicializar uma nova instância da WebControl classe usando o valor especificado System.Web.UI.HtmlTextWriterTag .Use this constructor to create and initialize a new instance of the WebControl class using the specified System.Web.UI.HtmlTextWriterTag value.

A tabela a seguir mostra o valor da propriedade inicial para uma instância do WebControl .The following table shows the initial property value for an instance of WebControl.

PropriedadeProperty Valor inicialInitial Value
TagKey O HtmlTextWriterTag valor de enumeração especificado pelo tag parâmetro.The HtmlTextWriterTag enumeration value specified by the tag parameter.

Confira também

Aplica-se a