ControlValuePropertyAttribute 類別

定義

指定 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
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type ControlValuePropertyAttribute = class
    inherit Attribute
Public NotInheritable Class ControlValuePropertyAttribute
Inherits Attribute
繼承
ControlValuePropertyAttribute
屬性

範例

下列程式碼範例示範如何將 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 ,您通常會藉由設定和屬性,將控制項的屬性系結至參數 ControlID PropertyNameWhen defining a ControlParameter object, you typically bind a control's property to a parameter by setting both the ControlID and PropertyName properties. 如果 PropertyName 未設定屬性,則會使用預設屬性。If the PropertyName property is not set, a default property is used. ControlValuePropertyAttribute屬性會套用至控制項,以指定 ControlParameter 物件在執行時間系結至的預設屬性。The 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 類別的新執行個體。Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name.

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 類別的新執行個體。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

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

Name

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

TypeId

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

(繼承來源 Attribute)

方法

Equals(Object)

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

GetHashCode()

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

GetType()

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

(繼承來源 Object)
IsDefaultAttribute()

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

(繼承來源 Attribute)
Match(Object)

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

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

明確介面實作

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

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

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

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

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

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

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

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

(繼承來源 Attribute)

適用於

另請參閱