UrlPropertyAttribute Construtores

Definição

Inicializa uma nova instância da classe UrlPropertyAttribute.

Sobrecargas

UrlPropertyAttribute()

Inicializa uma nova instância padrão da classe UrlPropertyAttribute.

UrlPropertyAttribute(String)

Inicializa uma nova instância da classe UrlPropertyAttribute, definindo a propriedade Filter para a cadeia de caracteres especificada.

UrlPropertyAttribute()

Inicializa uma nova instância padrão da classe UrlPropertyAttribute.

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

Exemplos

O exemplo de código a seguir demonstra uma classe que implementa uma propriedade específica de URL. Neste exemplo de código, um atributo padrão UrlPropertyAttribute é aplicado à TargetUrl propriedade da CustomHyperLinkControl classe. O atributo indica suporte para todos os tipos de URL e especifica um filtro de arquivo padrão definido como "*.*".

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

Comentários

Uma instância padrão da UrlPropertyAttribute classe é inicializada com a Filter propriedade definida como o valor "*.*".

Aplica-se a

UrlPropertyAttribute(String)

Inicializa uma nova instância da classe UrlPropertyAttribute, definindo a propriedade Filter para a cadeia de caracteres especificada.

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)

Parâmetros

filter
String

Um filtro de arquivo associado à propriedade específica da URL.

Exemplos

O exemplo de código a seguir demonstra uma classe que implementa uma propriedade específica de URL. Neste exemplo de código, um UrlPropertyAttribute atributo é aplicado à TargetUrl propriedade da CustomHyperLinkControl classe. O atributo define um filtro de arquivo específico para arquivos 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

Comentários

Uma instância de uma UrlPropertyAttribute classe criada com esse construtor é inicializada com a Filter propriedade definida como filter.

Aplica-se a