ControlValuePropertyAttribute 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定 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 AttributePublic NotInheritable Class ControlValuePropertyAttribute
Inherits Attribute- 继承
- 属性
示例
下面的代码示例演示如何将指定默认属性和值的属性应用于 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 对象时,通常通过设置 ControlID 和 PropertyName 属性将控件的 属性绑定到参数。 如果未设置属性 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) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |