Compartilhar via


ControlValuePropertyAttribute Construtores

Definição

Inicializa uma nova instância da classe ControlValuePropertyAttribute.

Sobrecargas

ControlValuePropertyAttribute(String)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade especificado.

ControlValuePropertyAttribute(String, Object)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade e o valor padrão especificados.

ControlValuePropertyAttribute(String, Type, String)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade e o valor padrão especificados. O valor padrão também é convertido para o tipo de dados especificado.

ControlValuePropertyAttribute(String)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade especificado.

public:
 ControlValuePropertyAttribute(System::String ^ name);
public ControlValuePropertyAttribute (string name);
new System.Web.UI.ControlValuePropertyAttribute : string -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String)

Parâmetros

name
String

A propriedade padrão para o controle.

Exemplos

O exemplo de código a seguir demonstra como aplicar um ControlValuePropertyAttribute atributo que especifica uma propriedade padrão a um controle personalizado. Esse construtor é chamado internamente por ASP.NET para criar um ControlValuePropertyAttribute objeto que representa o atributo.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Samples.AspNet.CS.Controls
{
    // Set ControlValueProperty attribute to specify the default
    // property of this control that a ControlParameter object 
    // binds to at run time.
    [DefaultProperty("Text")]
    [ControlValueProperty("Text")]
    public class SimpleCustomControl : WebControl
    {
        private string text;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
            }
        }

        protected override void Render(HtmlTextWriter output)
        {
            output.Write(Text);
        }
    }
}

Imports System.ComponentModel
Imports System.Web.UI

Namespace Samples.AspNet.VB.Controls

    ' Set ControlValueProperty attribute to specify the default
    ' property of this control that a ControlParameter object 
    ' binds to at run time.
    <DefaultProperty("Text"), ControlValueProperty("Text")> Public Class SimpleCustomControl
        Inherits System.Web.UI.WebControls.WebControl

        Dim _text As String

        <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
            Get
                Return _text
            End Get

            Set(ByVal Value As String)
                _text = Value
            End Set
        End Property

        Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
            output.Write([Text])
        End Sub

    End Class

End Namespace

Comentários

Use este construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado. A tabela a seguir mostra o valor da propriedade inicial de uma instância da ControlValuePropertyAttribute classe.

Propriedade Valor inicial
Name O valor do name parâmetro.

Confira também

Aplica-se a

ControlValuePropertyAttribute(String, Object)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade e o valor padrão especificados.

public:
 ControlValuePropertyAttribute(System::String ^ name, System::Object ^ defaultValue);
public ControlValuePropertyAttribute (string name, object defaultValue);
new System.Web.UI.ControlValuePropertyAttribute : string * obj -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String, defaultValue As Object)

Parâmetros

name
String

A propriedade padrão para o controle.

defaultValue
Object

O valor padrão para a propriedade padrão.

Exemplos

O exemplo de código a seguir demonstra como aplicar um ControlValuePropertyAttribute atributo que especifica uma propriedade padrão e um valor a um controle personalizado. Esse construtor é chamado internamente por ASP.NET para criar um ControlValuePropertyAttribute objeto que representa o atributo.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Samples.AspNet.CS.Controls
{
    // Set ControlValueProperty attribute to specify the default
    // property of this control that a ControlParameter object 
    // binds to at run time.
    [DefaultProperty("Text")]
    [ControlValueProperty("Text", "Default Text")]
    public class SimpleCustomControl : WebControl
    {
        private string text;

        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
            }
        }

        protected override void Render(HtmlTextWriter output)
        {
            output.Write(Text);
        }
    }
}

Imports System.ComponentModel
Imports System.Web.UI

Namespace Samples.AspNet.VB.Controls

    ' Set ControlValueProperty attribute to specify the default
    ' property of this control that a ControlParameter object 
    ' binds to at run time.
    <DefaultProperty("Text"), ControlValueProperty("Text", "DefaultText")> Public Class SimpleCustomControl
        Inherits System.Web.UI.WebControls.WebControl

        Dim _text As String

        <Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
            Get
                Return _text
            End Get

            Set(ByVal Value As String)
                _text = Value
            End Set
        End Property

        Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
            output.Write([Text])
        End Sub

    End Class

End Namespace

Comentários

Use esse construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade e o valor padrão especificados. A tabela a seguir mostra valores de propriedade iniciais para uma instância da ControlValuePropertyAttribute classe.

Propriedade Valor inicial
Name O valor do name parâmetro.
DefaultValue O valor do defaultValue parâmetro.

Confira também

Aplica-se a

ControlValuePropertyAttribute(String, Type, String)

Inicializa uma nova instância da classe ControlValuePropertyAttribute usando o nome da propriedade e o valor padrão especificados. O valor padrão também é convertido para o tipo de dados especificado.

public:
 ControlValuePropertyAttribute(System::String ^ name, Type ^ type, System::String ^ defaultValue);
public ControlValuePropertyAttribute (string name, Type type, string defaultValue);
new System.Web.UI.ControlValuePropertyAttribute : string * Type * string -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String, type As Type, defaultValue As String)

Parâmetros

name
String

A propriedade padrão para o controle.

type
Type

O Type para o qual o valor padrão é convertido.

defaultValue
String

O valor padrão para a propriedade padrão.

Comentários

Use esse construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade e o valor padrão especificados. Essa versão do construtor também tenta converter o valor padrão para o tipo de dados especificado pelo type parâmetro. Se o valor padrão não puder ser convertido, a DefaultValue propriedade não será definida. A tabela a seguir mostra valores de propriedade iniciais para uma instância da ControlValuePropertyAttribute classe.

Propriedade Valor inicial
Name O valor do name parâmetro.
DefaultValue O valor do defaultValue parâmetro, se o valor puder ser convertido no tipo de dados especificado pelo type parâmetro.

Confira também

Aplica-se a