UrlPropertyAttribute Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy UrlPropertyAttribute.

Przeciążenia

UrlPropertyAttribute()

Inicjuje UrlPropertyAttribute nowe domyślne wystąpienie klasy.

UrlPropertyAttribute(String)

Inicjuje UrlPropertyAttribute nowe wystąpienie klasy, ustawiając Filter właściwość na określony ciąg.

UrlPropertyAttribute()

Inicjuje UrlPropertyAttribute nowe domyślne wystąpienie klasy.

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

Przykłady

Poniższy przykład kodu przedstawia klasę, która implementuje właściwość specyficzną dla adresu URL. W tym przykładzie kodu do właściwości CustomHyperLinkControl klasy jest stosowany TargetUrl atrybut domyślnyUrlPropertyAttribute. Atrybut wskazuje obsługę wszystkich typów adresów URL i określa domyślny filtr pliku ustawiony 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

Uwagi

Domyślne wystąpienie UrlPropertyAttribute klasy jest inicjowane z Filter właściwością ustawioną na wartość "*.*".

Dotyczy

UrlPropertyAttribute(String)

Inicjuje UrlPropertyAttribute nowe wystąpienie klasy, ustawiając Filter właściwość na określony ciąg.

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 pliku skojarzony z właściwością specyficzną dla adresu URL.

Przykłady

Poniższy przykład kodu przedstawia klasę, która implementuje właściwość specyficzną dla adresu URL. W tym przykładzie UrlPropertyAttribute kodu atrybut jest stosowany do TargetUrl właściwości CustomHyperLinkControl klasy. Atrybut ustawia określony filtr plików dla plików 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

Uwagi

Wystąpienie klasy utworzonej UrlPropertyAttribute za pomocą tego konstruktora jest inicjowane z właściwością ustawioną Filter na filter.

Dotyczy