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
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对象时, 通常通过设置ControlIDPropertyName属性将控件的属性绑定到参数。When 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. 特性应用于控件, 以指定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 类的新实例。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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

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

将一组名称映射为对应的一组调度标识符。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)

适用于

另请参阅