Export (0) Print
Expand All

ControlValuePropertyAttribute Class

Specifies the default property of a control that a ControlParameter object binds to at run time. This class cannot be inherited.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

[AttributeUsageAttribute(AttributeTargets.Class)] 
public sealed class ControlValuePropertyAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public final class ControlValuePropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) 
public final class ControlValuePropertyAttribute extends Attribute
Not applicable.

When defining a ControlParameter object, you typically bind a control's property to a parameter by setting both the ControlID and PropertyName properties. If the PropertyName property is not set, a default property is used. 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 Extending Metadata Using Attributes.

For a list of initial property values for an instance of the ControlValuePropertyAttribute class, see the ControlValuePropertyAttribute constructor.

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);
        }
    }
}


System.Object
   System.Attribute
    System.Web.UI.ControlValuePropertyAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft