ControlValuePropertyAttribute 构造函数   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ControlValuePropertyAttribute 类的新实例。
重载
| ControlValuePropertyAttribute(String) | 使用指定的属性名称初始化 ControlValuePropertyAttribute 类的新实例。 | 
| ControlValuePropertyAttribute(String, Object) | 使用指定的属性名称和默认值初始化 ControlValuePropertyAttribute 类的新实例。 | 
| ControlValuePropertyAttribute(String, Type, String) | 使用指定的属性名称和默认值初始化 ControlValuePropertyAttribute 类的新实例。 该默认值也转换为指定的数据类型。 | 
ControlValuePropertyAttribute(String)
使用指定的属性名称初始化 ControlValuePropertyAttribute 类的新实例。
public:
 ControlValuePropertyAttribute(System::String ^ name);public ControlValuePropertyAttribute (string name);new System.Web.UI.ControlValuePropertyAttribute : string -> System.Web.UI.ControlValuePropertyAttributePublic Sub New (name As String)参数
- name
- String
控件的默认属性。
示例
下面的代码示例演示如何将指定 ControlValuePropertyAttribute 默认属性的属性应用于自定义控件。 此构造函数通过 ASP.NET 在内部调用,以创建表示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")]
    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")> 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
注解
使用此构造函数可以使用指定的属性名称创建类的新实例 ControlValuePropertyAttribute 。 下表显示了类实例 ControlValuePropertyAttribute 的初始属性值。
| properties | 初始值 | 
|---|---|
| Name | name参数的值。 | 
另请参阅
适用于
ControlValuePropertyAttribute(String, Object)
使用指定的属性名称和默认值初始化 ControlValuePropertyAttribute 类的新实例。
public:
 ControlValuePropertyAttribute(System::String ^ name, System::Object ^ defaultValue);public ControlValuePropertyAttribute (string name, object defaultValue);new System.Web.UI.ControlValuePropertyAttribute : string * obj -> System.Web.UI.ControlValuePropertyAttributePublic Sub New (name As String, defaultValue As Object)参数
- name
- String
控件的默认属性。
- defaultValue
- Object
默认属性的默认值。
示例
下面的代码示例演示如何将指定 ControlValuePropertyAttribute 默认属性和值的属性应用于自定义控件。 此构造函数通过 ASP.NET 在内部调用,以创建表示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
注解
使用此构造函数可以使用指定的属性名称和默认值创建类的新实例 ControlValuePropertyAttribute 。 下表显示了 ControlValuePropertyAttribute 类的某个实例的初始属性值。
| 属性 | 初始值 | 
|---|---|
| Name | name参数的值。 | 
| DefaultValue | defaultValue参数的值。 | 
另请参阅
适用于
ControlValuePropertyAttribute(String, Type, String)
使用指定的属性名称和默认值初始化 ControlValuePropertyAttribute 类的新实例。 该默认值也转换为指定的数据类型。
public:
 ControlValuePropertyAttribute(System::String ^ name, Type ^ type, System::String ^ defaultValue);public ControlValuePropertyAttribute (string name, Type type, string defaultValue);new System.Web.UI.ControlValuePropertyAttribute : string * Type * string -> System.Web.UI.ControlValuePropertyAttributePublic Sub New (name As String, type As Type, defaultValue As String)参数
- name
- String
控件的默认属性。
- defaultValue
- String
默认属性的默认值。
注解
使用此构造函数可以使用指定的属性名称和默认值创建类的新实例 ControlValuePropertyAttribute 。 此版本的构造函数还尝试将默认值转换为参数指定的 type 数据类型。 如果无法转换默认值,则 DefaultValue 不会设置该属性。 下表显示了 ControlValuePropertyAttribute 类的某个实例的初始属性值。
| 属性 | 初始值 | 
|---|---|
| Name | name参数的值。 | 
| DefaultValue | defaultValue如果值可以转换为参数指定的type数据类型,则为参数的值。 |