ControlValuePropertyAttribute Constructors

Definition

Initializes a new instance of the ControlValuePropertyAttribute class.

Overloads

ControlValuePropertyAttribute(String)

Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name.

ControlValuePropertyAttribute(String, Object)

Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name and default value.

ControlValuePropertyAttribute(String, Type, String)

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.

ControlValuePropertyAttribute(String)

Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name.

public:
 ControlValuePropertyAttribute(System::String ^ name);
public ControlValuePropertyAttribute (string name);
new System.Web.UI.ControlValuePropertyAttribute : string -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String)

Parameters

name
String

The default property for the control.

Examples

The following code example demonstrates how to apply a ControlValuePropertyAttribute attribute that specifies a default property to a custom control. This constructor is called internally by ASP.NET to create a ControlValuePropertyAttribute object that represents the attribute.


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

Remarks

Use this constructor to create a new instance of the ControlValuePropertyAttribute class using the specified property name. The following table shows the initial property value for an instance of the ControlValuePropertyAttribute class.

Property Initial value
Name The value of the name parameter.

See also

ControlValuePropertyAttribute(String, Object)

Initializes a new instance of the ControlValuePropertyAttribute class using the specified property name and default value.

public:
 ControlValuePropertyAttribute(System::String ^ name, System::Object ^ defaultValue);
public ControlValuePropertyAttribute (string name, object defaultValue);
new System.Web.UI.ControlValuePropertyAttribute : string * obj -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String, defaultValue As Object)

Parameters

name
String

The default property for the control.

defaultValue
Object

The default value for the default property.

Examples

The following code example demonstrates how to apply a ControlValuePropertyAttribute attribute that specifies a default property and value to a custom control. This constructor is called internally by ASP.NET to create a ControlValuePropertyAttribute object that represents the attribute.


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

Remarks

Use this constructor to create a new instance of the ControlValuePropertyAttribute class using the specified property name and default value. The following table shows initial property values for an instance of the ControlValuePropertyAttribute class.

Property Initial value
Name The value of the name parameter.
DefaultValue The value of the defaultValue parameter.

See also

ControlValuePropertyAttribute(String, Type, String)

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.

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.ControlValuePropertyAttribute

Parameters

name
String

The default property for the control.

type
Type

The Type to which the default value is converted.

defaultValue
String

The default value for the default property.

Remarks

Use this constructor to create a new instance of the ControlValuePropertyAttribute class using the specified property name and default value. This version of the constructor also attempts to convert the default value to the data type specified by the type parameter. If the default value cannot be converted, the DefaultValue property is not set. The following table shows initial property values for an instance of the ControlValuePropertyAttribute class.

Property Initial value
Name The value of the name parameter.
DefaultValue The value of the defaultValue parameter, if the value can be converted to the data type specified by the type parameter.

See also

Applies to