Bagikan melalui


ControlValuePropertyAttribute Konstruktor

Definisi

Menginisialisasi instans baru dari kelas ControlValuePropertyAttribute.

Overload

Nama Deskripsi
ControlValuePropertyAttribute(String)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti yang ditentukan.

ControlValuePropertyAttribute(String, Object)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan.

ControlValuePropertyAttribute(String, Type, String)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan. Nilai default juga dikonversi ke jenis data yang ditentukan.

ControlValuePropertyAttribute(String)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti yang ditentukan.

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)

Parameter

name
String

Properti default untuk kontrol.

Contoh

Contoh kode berikut menunjukkan cara menerapkan ControlValuePropertyAttribute atribut yang menentukan properti default ke kontrol kustom. Konstruktor ini dipanggil secara internal oleh ASP.NET untuk membuat ControlValuePropertyAttribute objek yang mewakili atribut .


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

Keterangan

Gunakan konstruktor ini untuk membuat instans ControlValuePropertyAttribute baru kelas menggunakan nama properti yang ditentukan. Tabel berikut menunjukkan nilai properti awal untuk instans ControlValuePropertyAttribute kelas.

Harta benda Nilai awal
Name Nilai name parameter .

Lihat juga

Berlaku untuk

ControlValuePropertyAttribute(String, Object)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan.

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)

Parameter

name
String

Properti default untuk kontrol.

defaultValue
Object

Nilai default untuk properti default.

Contoh

Contoh kode berikut menunjukkan cara menerapkan ControlValuePropertyAttribute atribut yang menentukan properti dan nilai default ke kontrol kustom. Konstruktor ini dipanggil secara internal oleh ASP.NET untuk membuat ControlValuePropertyAttribute objek yang mewakili atribut .


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

Keterangan

Gunakan konstruktor ini untuk membuat instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan. Tabel berikut ini memperlihatkan nilai properti awal untuk instans ControlValuePropertyAttribute kelas.

Harta benda Nilai awal
Name Nilai name parameter .
DefaultValue Nilai defaultValue parameter .

Lihat juga

Berlaku untuk

ControlValuePropertyAttribute(String, Type, String)

Menginisialisasi instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan. Nilai default juga dikonversi ke jenis data yang ditentukan.

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)

Parameter

name
String

Properti default untuk kontrol.

type
Type

tempat Type nilai default dikonversi.

defaultValue
String

Nilai default untuk properti default.

Keterangan

Gunakan konstruktor ini untuk membuat instans ControlValuePropertyAttribute baru kelas menggunakan nama properti dan nilai default yang ditentukan. Versi konstruktor ini juga mencoba mengonversi nilai default ke jenis data yang ditentukan oleh type parameter . Jika nilai default tidak dapat dikonversi, DefaultValue properti tidak diatur. Tabel berikut ini memperlihatkan nilai properti awal untuk instans ControlValuePropertyAttribute kelas.

Harta benda Nilai awal
Name Nilai name parameter .
DefaultValue Nilai defaultValue parameter, jika nilai dapat dikonversi ke jenis data yang ditentukan oleh type parameter .

Lihat juga

Berlaku untuk