UrlPropertyAttribute Конструкторы

Определение

Инициализирует новый экземпляр класса UrlPropertyAttribute.

Перегрузки

UrlPropertyAttribute()

Инициализирует новый экземпляр по умолчанию класса UrlPropertyAttribute.

UrlPropertyAttribute(String)

Выполняет инициализацию нового экземпляра класса UrlPropertyAttribute с присвоением указанной строке свойства Filter.

UrlPropertyAttribute()

Инициализирует новый экземпляр по умолчанию класса UrlPropertyAttribute.

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

Примеры

В следующем примере кода демонстрируется класс, реализующий свойство, зависящее от URL-адреса. В этом примере кода атрибут по умолчанию UrlPropertyAttribute применяется к свойству TargetUrlCustomHyperLinkControl класса . Атрибут указывает на поддержку всех типов URL-адресов и задает фильтр файлов по умолчанию, для параметра "*.*".

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

Комментарии

Экземпляр класса по умолчанию инициализируется UrlPropertyAttribute со Filter значением "*.*".

Применяется к

UrlPropertyAttribute(String)

Выполняет инициализацию нового экземпляра класса UrlPropertyAttribute с присвоением указанной строке свойства Filter.

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)

Параметры

filter
String

Сопоставление фильтра файлов с определяемым URL-адресом свойством.

Примеры

В следующем примере кода демонстрируется класс, реализующий свойство, зависящее от URL-адреса. В этом примере UrlPropertyAttribute кода атрибут применяется к свойству TargetUrlCustomHyperLinkControl класса . Атрибут задает определенный фильтр файлов для 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

Комментарии

Экземпляр класса, UrlPropertyAttribute созданный с помощью этого конструктора, инициализируется со свойством Filter , равным filter.

Применяется к