Bagikan melalui


UrlPropertyAttribute Konstruktor

Definisi

Menginisialisasi instans baru dari kelas UrlPropertyAttribute.

Overload

Nama Deskripsi
UrlPropertyAttribute()

Menginisialisasi instans default baru kelas UrlPropertyAttribute .

UrlPropertyAttribute(String)

Menginisialisasi instans UrlPropertyAttribute baru kelas, mengatur Filter properti ke string yang ditentukan.

UrlPropertyAttribute()

Menginisialisasi instans default baru kelas UrlPropertyAttribute .

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

Contoh

Contoh kode berikut menunjukkan kelas yang mengimplementasikan properti khusus URL. Dalam contoh kode ini, atribut default UrlPropertyAttribute diterapkan ke TargetUrl properti CustomHyperLinkControl kelas. Atribut menunjukkan dukungan untuk semua jenis URL dan menentukan filter file default yang diatur ke "*.*".

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

Keterangan

Instans default kelas diinisialisasi UrlPropertyAttribute dengan properti yang Filter diatur ke nilai "*.*".

Berlaku untuk

UrlPropertyAttribute(String)

Menginisialisasi instans UrlPropertyAttribute baru kelas, mengatur Filter properti ke string yang ditentukan.

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

Filter file yang terkait dengan properti khusus URL.

Contoh

Contoh kode berikut menunjukkan kelas yang mengimplementasikan properti khusus URL. Dalam contoh kode ini, UrlPropertyAttribute atribut diterapkan ke TargetUrl properti CustomHyperLinkControl kelas. Atribut menetapkan filter file tertentu untuk file 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

Keterangan

Instans kelas yang UrlPropertyAttribute dibuat dengan konstruktor ini diinisialisasi dengan properti yang Filter diatur ke filter.

Berlaku untuk