共用方式為


ControlValuePropertyAttribute 類別

定義

指定 ControlParameter 物件在運行時間系結至之控件的預設屬性。 無法繼承這個類別。

public ref class ControlValuePropertyAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class ControlValuePropertyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type ControlValuePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ControlValuePropertyAttribute
Inherits Attribute
繼承
ControlValuePropertyAttribute
屬性

範例

以下程式碼範例示範如何將 ControlValuePropertyAttribute 指定預設屬性與值的屬性套用到自訂控制項。


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

備註

在定義物件 ControlParameter 時,通常你會透過設定 ControlIDPropertyName 屬性來綁定控制項的屬性到參數。 若未設定該 PropertyName 屬性,則使用預設屬性。 屬性 ControlValuePropertyAttribute 套用到控制項上,以指定物件執行時綁定的預設屬性 ControlParameter

欲了解更多屬性的使用資訊,請參閱屬性。

如需 ControlValuePropertyAttribute 類別實例的初始屬性值清單,請參閱 ControlValuePropertyAttribute 建構函式。

建構函式

名稱 Description
ControlValuePropertyAttribute(String, Object)

使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。

ControlValuePropertyAttribute(String, Type, String)

使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。 預設值也會轉換成指定的資料型別。

ControlValuePropertyAttribute(String)

使用指定的屬性名稱初始化該 ControlValuePropertyAttribute 類別的新實例。

屬性

名稱 Description
DefaultValue

取得控制項預設屬性的預設值。

Name

取得控制項的預設屬性。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

判斷當前物件實例 ControlValuePropertyAttribute 是否等於指定的物件。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱