ControlValuePropertyAttribute Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da ControlValuePropertyAttribute classe.
Sobrecargas
| Name | Description |
|---|---|
| ControlValuePropertyAttribute(String) |
Inicializa uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado. |
| ControlValuePropertyAttribute(String, Object) |
Inicializa uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão. |
| ControlValuePropertyAttribute(String, Type, String) |
Inicializa uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão. O valor padrão também é convertido para o tipo de dado especificado. |
ControlValuePropertyAttribute(String)
Inicializa uma nova instância da ControlValuePropertyAttribute classe 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 do controlo.
Exemplos
O exemplo de código seguinte demonstra como aplicar um ControlValuePropertyAttribute atributo que especifica uma propriedade por defeito a um controlo personalizado. Este construtor é chamado internamente por ASP.NET para criar um objeto ControlValuePropertyAttribute 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
Observações
Use este construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado. A tabela seguinte mostra o valor inicial da propriedade para uma instância da ControlValuePropertyAttribute classe.
| Property | Valor inicial |
|---|---|
| Name | O valor do name parâmetro. |
Ver também
Aplica-se a
ControlValuePropertyAttribute(String, Object)
Inicializa uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão.
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 do controlo.
- defaultValue
- Object
O valor padrão da propriedade por defeito.
Exemplos
O exemplo de código seguinte demonstra como aplicar um ControlValuePropertyAttribute atributo que especifica uma propriedade e valor predefinidos a um controlo personalizado. Este construtor é chamado internamente por ASP.NET para criar um objeto ControlValuePropertyAttribute 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
Observações
Use este construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão. A tabela seguinte mostra os valores iniciais das propriedades para uma instância da ControlValuePropertyAttribute classe.
| Property | Valor inicial |
|---|---|
| Name | O valor do name parâmetro. |
| DefaultValue | O valor do defaultValue parâmetro. |
Ver também
Aplica-se a
ControlValuePropertyAttribute(String, Type, String)
Inicializa uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão. O valor padrão também é convertido para o tipo de dado 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 do controlo.
- defaultValue
- String
O valor padrão da propriedade por defeito.
Observações
Use este construtor para criar uma nova instância da ControlValuePropertyAttribute classe usando o nome da propriedade especificado e o valor padrão. Esta versão do construtor também tenta converter o valor padrão para o tipo de dado especificado pelo type parâmetro. Se o valor padrão não puder ser convertido, a DefaultValue propriedade não é definida. A tabela seguinte mostra os valores iniciais das propriedades para uma instância da ControlValuePropertyAttribute classe.
| Property | Valor inicial |
|---|---|
| Name | O valor do name parâmetro. |
| DefaultValue | O valor do defaultValue parâmetro, se o valor puder ser convertido para o tipo de dado especificado pelo type parâmetro. |