Freigeben über


UrlPropertyAttribute Konstruktoren

Definition

Initialisiert eine neue Instanz der UrlPropertyAttribute-Klasse.

Überlädt

Name Beschreibung
UrlPropertyAttribute()

Initialisiert eine neue Standardinstanz der UrlPropertyAttribute Klasse.

UrlPropertyAttribute(String)

Initialisiert eine neue Instanz der UrlPropertyAttribute Klasse, wobei die Filter Eigenschaft auf die angegebene Zeichenfolge festgelegt wird.

UrlPropertyAttribute()

Initialisiert eine neue Standardinstanz der UrlPropertyAttribute Klasse.

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

Beispiele

Im folgenden Codebeispiel wird eine Klasse veranschaulicht, die eine URL-spezifische Eigenschaft implementiert. In diesem Codebeispiel wird ein Standardattribute UrlPropertyAttribute auf die TargetUrl Eigenschaft der CustomHyperLinkControl Klasse angewendet. Das Attribut gibt die Unterstützung für alle URL-Typen an und gibt einen Standarddateifilter auf "*.*" an.

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

Hinweise

Eine Standardinstanz der UrlPropertyAttribute Klasse wird initialisiert, wobei die Filter Eigenschaft auf den Wert "*.*" festgelegt ist.

Gilt für:

UrlPropertyAttribute(String)

Initialisiert eine neue Instanz der UrlPropertyAttribute Klasse, wobei die Filter Eigenschaft auf die angegebene Zeichenfolge festgelegt wird.

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)

Parameter

filter
String

Ein Dateifilter, der der URL-spezifischen Eigenschaft zugeordnet ist.

Beispiele

Im folgenden Codebeispiel wird eine Klasse veranschaulicht, die eine URL-spezifische Eigenschaft implementiert. In diesem Codebeispiel wird ein UrlPropertyAttribute Attribut auf die TargetUrl Eigenschaft der CustomHyperLinkControl Klasse angewendet. Das Attribut legt einen bestimmten Dateifilter für ASP.NET Dateien fest.

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

Hinweise

Eine Instanz einer UrlPropertyAttribute klasse, die mit diesem Konstruktor erstellt wurde, wird mit der Filter Aufsatzeigenschaft filterinitialisiert.

Gilt für: