ControlValuePropertyAttribute 建構函式

定義

初始化 ControlValuePropertyAttribute 類別的新執行個體。

多載

ControlValuePropertyAttribute(String)

初始化使用指定的屬性名稱之 ControlValuePropertyAttribute 類別的新執行個體。

ControlValuePropertyAttribute(String, Object)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。

ControlValuePropertyAttribute(String, Type, String)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。 預設值也會轉換成指定的資料型別。

ControlValuePropertyAttribute(String)

初始化使用指定的屬性名稱之 ControlValuePropertyAttribute 類別的新執行個體。

C#
public ControlValuePropertyAttribute (string name);

參數

name
String

控制項的預設屬性。

範例

下列程式碼範例示範如何將指定預設屬性的屬性套用 ControlValuePropertyAttribute 至自訂控制項。 這個建構函式會由 ASP.NET 內部呼叫,以建立 ControlValuePropertyAttribute 代表 屬性的 物件。

C#

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);
        }
    }
}

備註

使用此建構函式,使用指定的屬性名稱建立 類別的新實例 ControlValuePropertyAttribute 。 下表顯示 類別實例 ControlValuePropertyAttribute 的初始屬性值。

屬性 初始值
Name name 參數的值。

另請參閱

適用於

.NET Framework 4.8 及其他版本
產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

ControlValuePropertyAttribute(String, Object)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。

C#
public ControlValuePropertyAttribute (string name, object defaultValue);

參數

name
String

控制項的預設屬性。

defaultValue
Object

預設屬性的預設值。

範例

下列程式碼範例示範如何將指定預設屬性和值的屬性套用 ControlValuePropertyAttribute 至自訂控制項。 這個建構函式會由 ASP.NET 內部呼叫,以建立 ControlValuePropertyAttribute 代表 屬性的 物件。

C#

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);
        }
    }
}

備註

使用此建構函式,使用指定的屬性名稱和預設值,建立 類別的新實例 ControlValuePropertyAttribute 。 下表所顯示的是 ControlValuePropertyAttribute 類別之執行個體的初始屬性值。

屬性 初始值
Name name 參數的值。
DefaultValue defaultValue 參數的值。

另請參閱

適用於

.NET Framework 4.8 及其他版本
產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

ControlValuePropertyAttribute(String, Type, String)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。 預設值也會轉換成指定的資料型別。

C#
public ControlValuePropertyAttribute (string name, Type type, string defaultValue);

參數

name
String

控制項的預設屬性。

type
Type

預設值所轉換的目標 Type

defaultValue
String

預設屬性的預設值。

備註

使用此建構函式,使用指定的屬性名稱和預設值,建立 類別的新實例 ControlValuePropertyAttribute 。 這個版本的建構函式也會嘗試將預設值轉換為 參數所 type 指定的資料類型。 如果無法轉換預設值, DefaultValue 則不會設定 屬性。 下表所顯示的是 ControlValuePropertyAttribute 類別之執行個體的初始屬性值。

屬性 初始值
Name name 參數的值。
DefaultValue 如果值可以轉換成 參數所 type 指定的資料類型,則為 參數的值 defaultValue

另請參閱

適用於

.NET Framework 4.8 及其他版本
產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8