ControlValuePropertyAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ControlValuePropertyAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ControlValuePropertyAttribute(String) |
使用指定的屬性名稱初始化該 ControlValuePropertyAttribute 類別的新實例。 |
| ControlValuePropertyAttribute(String, Object) |
使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。 |
| ControlValuePropertyAttribute(String, Type, String) |
使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。 預設值也會轉換成指定的資料型別。 |
ControlValuePropertyAttribute(String)
使用指定的屬性名稱初始化該 ControlValuePropertyAttribute 類別的新實例。
public:
ControlValuePropertyAttribute(System::String ^ name);
public ControlValuePropertyAttribute(string name);
new System.Web.UI.ControlValuePropertyAttribute : string -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String)
參數
- name
- String
控制的預設屬性。
範例
以下程式碼範例示範如何套用 ControlValuePropertyAttribute 一個屬性,指定預設屬性給自訂控制項。 ASP.NET 內部呼叫此建構子以建立 ControlValuePropertyAttribute 代表該屬性的物件。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Samples.AspNet.CS.Controls
{
// Set ControlValueProperty attribute to specify the default
// property of this control that a ControlParameter object
// binds to at run time.
[DefaultProperty("Text")]
[ControlValueProperty("Text")]
public class SimpleCustomControl : WebControl
{
private string text;
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
Imports System.ComponentModel
Imports System.Web.UI
Namespace Samples.AspNet.VB.Controls
' Set ControlValueProperty attribute to specify the default
' property of this control that a ControlParameter object
' binds to at run time.
<DefaultProperty("Text"), ControlValueProperty("Text")> Public Class SimpleCustomControl
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.Write([Text])
End Sub
End Class
End Namespace
備註
使用此建構子建立一個新的類別實例 ControlValuePropertyAttribute ,使用指定的屬性名稱。 下表顯示該 ControlValuePropertyAttribute 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Name | 參數的 name 值。 |
另請參閱
適用於
ControlValuePropertyAttribute(String, Object)
使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。
public:
ControlValuePropertyAttribute(System::String ^ name, System::Object ^ defaultValue);
public ControlValuePropertyAttribute(string name, object defaultValue);
new System.Web.UI.ControlValuePropertyAttribute : string * obj -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String, defaultValue As Object)
參數
- name
- String
控制的預設屬性。
- defaultValue
- Object
預設屬性的預設值。
範例
以下程式碼範例示範如何將 ControlValuePropertyAttribute 指定預設屬性與值的屬性套用到自訂控制項。 ASP.NET 內部呼叫此建構子以建立 ControlValuePropertyAttribute 代表該屬性的物件。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Samples.AspNet.CS.Controls
{
// Set ControlValueProperty attribute to specify the default
// property of this control that a ControlParameter object
// binds to at run time.
[DefaultProperty("Text")]
[ControlValueProperty("Text", "Default Text")]
public class SimpleCustomControl : WebControl
{
private string text;
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
Imports System.ComponentModel
Imports System.Web.UI
Namespace Samples.AspNet.VB.Controls
' Set ControlValueProperty attribute to specify the default
' property of this control that a ControlParameter object
' binds to at run time.
<DefaultProperty("Text"), ControlValueProperty("Text", "DefaultText")> Public Class SimpleCustomControl
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]() As String
Get
Return _text
End Get
Set(ByVal Value As String)
_text = Value
End Set
End Property
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
output.Write([Text])
End Sub
End Class
End Namespace
備註
使用此建構子,使用指定的屬性名稱與預設值建立新的類別實例 ControlValuePropertyAttribute 。 下表顯示該 ControlValuePropertyAttribute 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Name | 參數的 name 值。 |
| DefaultValue | 參數的 defaultValue 值。 |
另請參閱
適用於
ControlValuePropertyAttribute(String, Type, String)
使用指定的屬性名稱和預設值初始化該 ControlValuePropertyAttribute 類別的新實例。 預設值也會轉換成指定的資料型別。
public:
ControlValuePropertyAttribute(System::String ^ name, Type ^ type, System::String ^ defaultValue);
public ControlValuePropertyAttribute(string name, Type type, string defaultValue);
new System.Web.UI.ControlValuePropertyAttribute : string * Type * string -> System.Web.UI.ControlValuePropertyAttribute
Public Sub New (name As String, type As Type, defaultValue As String)
參數
- name
- String
控制的預設屬性。
- defaultValue
- String
預設屬性的預設值。
備註
使用此建構子,使用指定的屬性名稱與預設值建立新的類別實例 ControlValuePropertyAttribute 。 此版本的建構子也會嘗試將預設值轉換為參數指定的 type 資料型態。 如果預設值無法轉換,該 DefaultValue 屬性就不會被設定。 下表顯示該 ControlValuePropertyAttribute 類別實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Name | 參數的 name 值。 |
| DefaultValue |
defaultValue參數值,如果該值能轉換為參數指定的type資料型態。 |