ControlValuePropertyAttribute.Name Propriété

Définition

Obtient la propriété par défaut d'un contrôle.

C#
public string Name { get; }

Valeur de propriété

String

Propriété par défaut d'un contrôle.

Exemples

L’exemple de code suivant montre comment définir la Name propriété en appliquant un ControlValuePropertyAttribute attribut à un contrôle personnalisé.

C#

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

Remarques

Lorsqu’un ControlParameter objet est défini sans son PropertyName jeu de propriétés, utilisez la Name propriété pour déterminer la propriété par défaut liée à l’objet au moment de l’exécution ControlParameter .

S’applique à

Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

Voir aussi