UrlPropertyAttribute Constructeurs

Définition

Initialise une nouvelle instance de la classe UrlPropertyAttribute.

Surcharges

UrlPropertyAttribute()

Initialise une nouvelle instance par défaut de la classe UrlPropertyAttribute.

UrlPropertyAttribute(String)

Initialise une nouvelle instance de la classe UrlPropertyAttribute, en affectant à la propriété Filter la chaîne spécifiée.

UrlPropertyAttribute()

Initialise une nouvelle instance par défaut de la classe UrlPropertyAttribute.

public:
 UrlPropertyAttribute();
public UrlPropertyAttribute ();
Public Sub New ()

Exemples

L’exemple de code suivant illustre une classe qui implémente une propriété spécifique à une URL. Dans cet exemple de code, un attribut par défaut UrlPropertyAttribute est appliqué à la TargetUrl propriété de la CustomHyperLinkControl classe . L’attribut indique la prise en charge de tous les types d’URL et spécifie un filtre de fichier par défaut défini sur « *.* ».

public class CustomHyperLinkControl : WebControl
{
    public CustomHyperLinkControl() { }

    // The TargetUrl property represents the URL that 
    // the custom hyperlink control navigates to.
    [UrlProperty()]
    public string TargetUrl
    {
        get
        {
            string s = (string)ViewState["TargetUrl"];
            return ((s == null) ? String.Empty : s);
        }
        set
        {
            ViewState["TargetUrl"] = value;
        }
    }

    // The Text property represents the visible text that 
    // the custom hyperlink control is displayed with.        
    public virtual string Text
    {
        get
        {
            string s = (string)ViewState["Text"];
            return ((s == null) ? String.Empty : s);
        }
        set
        {
            ViewState["Text"] = value;
        }
    }

    // Implement this method to render the control.
}
Public Class CustomHyperLinkControl
    Inherits WebControl

    Public Sub New()
    End Sub

    ' The TargetUrl property represents the URL that 
    ' the custom hyperlink control navigates to.        
    <UrlProperty()> _
    Public Property TargetUrl() As String
        Get
            Dim s As String = CStr(ViewState("TargetUrl"))
            If (s Is Nothing) Then
                Return String.Empty
            Else
                Return s
            End If
        End Get
        Set(ByVal value As String)
            ViewState("TargetUrl") = value
        End Set
    End Property

    ' The Text property represents the visible text that 
    ' the custom hyperlink control is displayed with.        

    Public Overridable Property [Text]() As String
        Get
            Dim s As String = CStr(ViewState("Text"))
            If (s Is Nothing) Then
                Return String.Empty
            Else
                Return s
            End If
        End Get
        Set(ByVal value As String)
            ViewState("Text") = value
        End Set
    End Property

    ' Implement method to render the control.

End Class

Remarques

Une instance par défaut de la UrlPropertyAttribute classe est initialisée avec la Filter propriété définie sur la valeur « *.* ».

S’applique à

UrlPropertyAttribute(String)

Initialise une nouvelle instance de la classe UrlPropertyAttribute, en affectant à la propriété Filter la chaîne spécifiée.

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

Paramètres

filter
String

Filtre de fichiers associé à la propriété URL spécifique.

Exemples

L’exemple de code suivant illustre une classe qui implémente une propriété spécifique à une URL. Dans cet exemple de code, un UrlPropertyAttribute attribut est appliqué à la TargetUrl propriété de la CustomHyperLinkControl classe . L’attribut définit un filtre de fichiers spécifique pour ASP.NET fichiers.

public class CustomHyperLinkControl : WebControl
{
    public CustomHyperLinkControl() { }

    // The TargetUrl property represents the URL that 
    // the custom hyperlink control navigates to.
    [UrlProperty("*.aspx")]
    public string TargetUrl
    {
        get
        {
            string s = (string)ViewState["TargetUrl"];
            return ((s == null) ? String.Empty : s);
        }
        set
        {
            ViewState["TargetUrl"] = value;
        }
    }

    // The Text property represents the visible text that 
    // the custom hyperlink control is displayed with.        
    public virtual string Text
    {
        get
        {
            string s = (string)ViewState["Text"];
            return ((s == null) ? String.Empty : s);
        }
        set
        {
            ViewState["Text"] = value;
        }
    }

    // Implement method to render the control.
}
Public Class CustomHyperLinkControl
    Inherits WebControl

    Public Sub New()
    End Sub

    ' The TargetUrl property represents the URL that 
    ' the custom hyperlink control navigates to.        
    <UrlProperty("*.aspx")> _
    Public Property TargetUrl() As String
        Get
            Dim s As String = CStr(ViewState("TargetUrl"))
            If (s Is Nothing) Then
                Return String.Empty
            Else
                Return s
            End If
        End Get
        Set(ByVal value As String)
            ViewState("TargetUrl") = value
        End Set
    End Property

    ' The Text property represents the visible text that 
    ' the custom hyperlink control is displayed with.                
    Public Overridable Property [Text]() As String
        Get
            Dim s As String = CStr(ViewState("Text"))
            If (s Is Nothing) Then
                Return String.Empty
            Else
                Return s
            End If
        End Get
        Set(ByVal value As String)
            ViewState("Text") = value
        End Set
    End Property

    ' Implement method to render the control.

End Class

Remarques

Une instance d’une UrlPropertyAttribute classe créée avec ce constructeur est initialisée avec la Filter propriété définie sur filter.

S’applique à