UrlPropertyAttribute Constructores

Definición

Inicializa una nueva instancia de la clase UrlPropertyAttribute.

Sobrecargas

UrlPropertyAttribute()

Inicializa una nueva instancia predeterminada de la clase UrlPropertyAttribute.

UrlPropertyAttribute(String)

Inicializa una nueva instancia de la clase UrlPropertyAttribute, estableciendo la propiedad Filter en la cadena especificada.

UrlPropertyAttribute()

Inicializa una nueva instancia predeterminada de la clase UrlPropertyAttribute.

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

Ejemplos

En el ejemplo de código siguiente se muestra una clase que implementa una propiedad específica de la dirección URL. En este ejemplo de código, se aplica un atributo predeterminado UrlPropertyAttribute a la TargetUrl propiedad de la CustomHyperLinkControl clase . El atributo indica la compatibilidad con todos los tipos de dirección URL y especifica un filtro de archivo predeterminado establecido en "*.*".

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

Comentarios

Una instancia predeterminada de la UrlPropertyAttribute clase se inicializa con la Filter propiedad establecida en el valor "*.*".

Se aplica a

UrlPropertyAttribute(String)

Inicializa una nueva instancia de la clase UrlPropertyAttribute, estableciendo la propiedad Filter en la cadena 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

Un filtro de archivos asociado a la propiedad específica de la dirección URL.

Ejemplos

En el ejemplo de código siguiente se muestra una clase que implementa una propiedad específica de la dirección URL. En este ejemplo de código, se aplica un UrlPropertyAttribute atributo a la TargetUrl propiedad de la CustomHyperLinkControl clase . El atributo establece un filtro de archivo específico para ASP.NET archivos.

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

Comentarios

Una instancia de una UrlPropertyAttribute clase creada con este constructor se inicializa con la Filter propiedad establecida en filter.

Se aplica a