UrlPropertyAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 UrlPropertyAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| UrlPropertyAttribute() |
初始化該類別的新預設實例 UrlPropertyAttribute 。 |
| UrlPropertyAttribute(String) |
初始化該類別的新實例 UrlPropertyAttribute ,並將屬性設定 Filter 為指定的字串。 |
UrlPropertyAttribute()
初始化該類別的新預設實例 UrlPropertyAttribute 。
public:
UrlPropertyAttribute();
public UrlPropertyAttribute();
Public Sub New ()
範例
以下程式碼範例展示了一個實作 URL 特定屬性的類別。 在這個程式碼範例中,類別的屬性CustomHyperLinkControl被套用TargetUrl一個預設UrlPropertyAttribute屬性。 該屬性表示支援所有 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 屬性被套用到 TargetUrl 類別的 CustomHyperLinkControl 屬性上。 屬性會為 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。