Sdílet prostřednictvím


UrlPropertyAttribute Konstruktory

Definice

Inicializuje novou instanci UrlPropertyAttribute třídy.

Přetížení

UrlPropertyAttribute()

Inicializuje novou výchozí instanci UrlPropertyAttribute třídy.

UrlPropertyAttribute(String)

Inicializuje novou instanci UrlPropertyAttribute třídy a nastaví Filter vlastnost na zadaný řetězec.

UrlPropertyAttribute()

Inicializuje novou výchozí instanci UrlPropertyAttribute třídy.

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

Příklady

Následující příklad kódu ukazuje třídu, která implementuje vlastnost specifickou pro adresu URL. V tomto příkladu kódu se na vlastnost CustomHyperLinkControl třídy použije TargetUrl výchozí UrlPropertyAttribute atribut. Atribut označuje podporu pro všechny typy adres URL a určuje výchozí filtr souborů nastavený na *.*.

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

Poznámky

Výchozí instance UrlPropertyAttribute třídy je inicializována s Filter vlastností nastavenou na hodnotu "*.*".

Platí pro

UrlPropertyAttribute(String)

Inicializuje novou instanci UrlPropertyAttribute třídy a nastaví Filter vlastnost na zadaný řetězec.

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)

Parametry

filter
String

Filtr souborů přidružený k vlastnosti specifické pro adresu URL.

Příklady

Následující příklad kódu ukazuje třídu, která implementuje vlastnost specifickou pro adresu URL. V tomto příkladu UrlPropertyAttribute kódu se atribut použije na TargetUrl vlastnost CustomHyperLinkControl třídy. Atribut nastaví konkrétní filtr souborů pro soubory ASP.NET.

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

Poznámky

Instance třídy vytvořené pomocí tohoto konstruktoru UrlPropertyAttribute je inicializována vlastností nastavena Filter na filter.

Platí pro