ControlValuePropertyAttribute ControlValuePropertyAttribute ControlValuePropertyAttribute ControlValuePropertyAttribute Class

定義

指定 ControlParameter 物件於執行階段所繫結的控制項預設屬性。Specifies the default property of a control that a ControlParameter object binds to at run time. 這個類別無法被繼承。This class cannot be inherited.

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

範例

下列程式碼範例示範如何將ControlValuePropertyAttribute指定預設屬性和值的屬性套用至自訂控制項。The following code example demonstrates how to apply a ControlValuePropertyAttribute attribute that specifies a default property and value to a custom control.


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屬性, 將控制項的屬性系結至參數。When defining a ControlParameter object, you typically bind a control's property to a parameter by setting both the ControlID and PropertyName properties. 如果未設定屬性, 則會使用預設屬性。 PropertyNameIf the PropertyName property is not set, a default property is used. 屬性會套用至控制項, 以指定ControlParameter物件在執行時間所系結的預設屬性。 ControlValuePropertyAttributeThe ControlValuePropertyAttribute attribute is applied to a control to specify its default property that a ControlParameter object binds to at run time.

如需使用屬性的詳細資訊, 請參閱屬性For more information about using attributes, see Attributes.

如需 ControlValuePropertyAttribute 類別之執行個體的初始屬性值清單,請參閱 ControlValuePropertyAttribute 建構函式。For a list of initial property values for an instance of the ControlValuePropertyAttribute class, see the ControlValuePropertyAttribute constructor.

建構函式

ControlValuePropertyAttribute(String) ControlValuePropertyAttribute(String) ControlValuePropertyAttribute(String) ControlValuePropertyAttribute(String)

使用指定的屬性名稱,初始化 ControlValuePropertyAttribute 類別的新執行個體。Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name.

ControlValuePropertyAttribute(String, Object) ControlValuePropertyAttribute(String, Object) ControlValuePropertyAttribute(String, Object) ControlValuePropertyAttribute(String, Object)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name and default value.

ControlValuePropertyAttribute(String, Type, String) ControlValuePropertyAttribute(String, Type, String) ControlValuePropertyAttribute(String, Type, String) ControlValuePropertyAttribute(String, Type, String)

使用指定的屬性名稱和預設值,初始化 ControlValuePropertyAttribute 類別的新執行個體。Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name and default value. 預設值也會轉換成指定的資料型別。The default value is also converted to the specified data type.

屬性

DefaultValue DefaultValue DefaultValue DefaultValue

取得控制項預設屬性的預設值。Gets the default value for the default property of a control.

Name Name Name Name

取得控制項的預設屬性。Gets the default property for a control.

TypeId TypeId TypeId TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷 ControlValuePropertyAttribute 物件目前的執行個體是否等於指定的物件。Determines whether the current instance of the ControlValuePropertyAttribute object is equal to the specified object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用於

另請參閱