DataBindingHandlerAttribute 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 DataBindingHandlerAttribute 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| DataBindingHandlerAttribute() |
初始化一個新的類別實例 DataBindingHandlerAttribute ,使用無參數。 這就是無參數建構子。 |
| DataBindingHandlerAttribute(String) |
初始化一個以指定類型名稱的新 DataBindingHandlerAttribute 類別實例。 |
| DataBindingHandlerAttribute(Type) |
初始化指定DataBindingHandlerAttribute類別 的新實例Type。 |
DataBindingHandlerAttribute()
初始化一個新的類別實例 DataBindingHandlerAttribute ,使用無參數。 這就是無參數建構子。
public:
DataBindingHandlerAttribute();
public DataBindingHandlerAttribute();
Public Sub New ()
範例
以下程式碼範例使用了建 DataBindingHandlerAttribute 構子。
// The following example uses the Default
// DataBindingHandlerAttribute constructor.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
namespace MyTextCustomControl
{
[ DataBindingHandlerAttribute() ]
[AspNetHostingPermission(SecurityAction.Demand,
Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class MyTextBox : TextBox
{
protected override void Render(HtmlTextWriter output)
{
output.Write("This class uses the DataBindingHandlerAttribute class.");
}
}
}
' The following example uses the Default
' DataBindingHandlerAttribute constructor.
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Namespace MyTextCustomControl
<DataBindingHandlerAttribute()> _
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class MyTextBox
Inherits TextBox
Protected Overrides Sub Render(output As HtmlTextWriter)
output.Write("This class uses the DataBindingHandlerAttribute class.")
End Sub
End Class
End Namespace 'MyTextCustomControl
適用於
DataBindingHandlerAttribute(String)
初始化一個以指定類型名稱的新 DataBindingHandlerAttribute 類別實例。
public:
DataBindingHandlerAttribute(System::String ^ typeName);
public DataBindingHandlerAttribute(string typeName);
new System.Web.UI.DataBindingHandlerAttribute : string -> System.Web.UI.DataBindingHandlerAttribute
Public Sub New (typeName As String)
參數
範例
以下程式碼範例使用 DataBindingHandlerAttribute 建構子來指定 Web 控制的自訂 DataBindingHandler 類別。
// The following example uses the
// DataBindingHandlerAttribute(String) constructor to designate
// the custom DataBindingHandler class, named MyDataBindingHandler,
// for the custom MyWebControl class.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel.Design;
using System.Security.Permissions;
namespace MyTextCustomControl
{
[ DataBindingHandlerAttribute("MyTextCustomControl.MyDataBindingHandler") ]
[AspNetHostingPermission(SecurityAction.Demand,
Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class MyWebControl : WebControl
{
protected override void Render(HtmlTextWriter output)
{
output.Write("This class uses the DataBindingHandlerAttribute class.");
}
}
public class MyDataBindingHandler : TextDataBindingHandler
{
public override void DataBindControl(IDesignerHost host, Control myControl)
{
((TextBox)myControl).Text = "Added by MyDataBindingHandler";
}
}
}
' The following example uses the
' DataBindingHandlerAttribute(String) constructor to designate
' the custom DataBindingHandler class, named MyDataBindingHandler,
' for the custom MyWebControl class.
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design
Imports System.ComponentModel.Design
Imports System.Security.Permissions
Namespace MyTextCustomControl
<DataBindingHandlerAttribute("MyTextCustomControl.MyDataBindingHandler")> _
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class MyWebControl
Inherits WebControl
Protected Overrides Sub Render(output As HtmlTextWriter)
output.Write("This class uses the DataBindingHandlerAttribute class.")
End Sub
End Class
Public Class MyDataBindingHandler
Inherits TextDataBindingHandler
Public Overrides Sub DataBindControl(host As IDesignerHost, myControl As Control)
CType(myControl, TextBox).Text = "Added by MyDataBindingHandler"
End Sub
End Class
End Namespace 'MyTextCustomControl
備註
此構造器的型別名稱是該類型的完全限定名稱,包括其組裝名稱。
適用於
DataBindingHandlerAttribute(Type)
初始化指定DataBindingHandlerAttribute類別 的新實例Type。
public:
DataBindingHandlerAttribute(Type ^ type);
public DataBindingHandlerAttribute(Type type);
new System.Web.UI.DataBindingHandlerAttribute : Type -> System.Web.UI.DataBindingHandlerAttribute
Public Sub New (type As Type)
參數
範例
以下程式碼範例定義了一個資料綁定處理器,名為 MyDataBindingHandler,供設計者在編輯模式下使用。 退出編輯模式後, Text 屬性值會顯示出來。
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace CustomControls
{
[
DataBindingHandler(typeof(MyDataBindingHandler)),
ToolboxData("<{0}:MyLabel runat=server></{0}:MyLabel>")
]
public class MyLabel : Label
{
public MyLabel()
{
// Insert your code here.
}
}
public class MyDataBindingHandler : DataBindingHandler
{
public override void DataBindControl(IDesignerHost host, Control control)
{
((Label)control).Text = "Added by data binding handler.";
}
}
}
Namespace CustomControls
<DataBindingHandler(GetType(MyDataBindingHandler)), ToolboxData("<{0}:MyLabel runat=server></{0}:MyLabel>")> _
Public Class MyLabel
Inherits Label
Public Sub New()
'Insert your code here.
End Sub
End Class
Public Class MyDataBindingHandler
Inherits DataBindingHandler
Public Overrides Sub DataBindControl(host As IDesignerHost, control As Control)
CType(control, Label).Text = "Added by data binding handler."
End Sub
End Class
End Namespace 'CustomControls
備註
此屬性的語法為:
[DataBindingHandlerAttribute
(typeof(dataBindingHandlerType))]