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