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 建構函式。

建構函式

ControlValuePropertyAttribute(String)

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

ControlValuePropertyAttribute(String, Object)

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

ControlValuePropertyAttribute(String, Type, String)

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

屬性

DefaultValue

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

Name

取得控制項的預設屬性。

TypeId

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

(繼承來源 Attribute)

方法

Equals(Object)

判斷 ControlValuePropertyAttribute 物件目前的執行個體是否等於指定的物件。

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

_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)

適用於

另請參閱