CheckBox-Konstruktor
Initialisiert eine neue Instanz der CheckBox-Klasse.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Sub New
'Usage
Dim instance As New CheckBox
public CheckBox ()
public:
CheckBox ()
public CheckBox ()
public function CheckBox ()
Hinweise
Mit diesem Konstruktor können Sie eine neue Instanz der CheckBox-Klasse erstellen und initialisieren.
Beispiel
Hinweis
Im folgenden Codebeispiel wird das Einzeldatei-Codemodell verwendet. Das Beispiel funktioniert möglicherweise nicht, wenn es direkt in eine CodeBehind-Datei kopiert wird. Dieses Codebeispiel muss in eine leere Textdatei mit einer ASPX-Erweiterung kopiert werden. Weitere Informationen zum Web Forms-Codemodell finden Sie unter Codemodell für ASP.NET-Webseiten.
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Create new CheckBox control.
Dim NewCheckBox As CheckBox = New CheckBox()
NewCheckBox.ID="FeatureCheckBox"
NewCheckBox.Text="Enable feature"
NewCheckBox.AutoPostBack = True
' Register the event handling method for the CheckedChanged event.
AddHandler NewCheckBox.CheckedChanged, AddressOf Check_Change
' Add the control to the Controls collection of the
' PlaceHolder control.
Place.Controls.Clear()
Place.Controls.Add(NewCheckBox)
End Sub
Sub Check_Change(sender As Object, e As EventArgs)
' Retrieve the CheckBox control from the PlaceHolder control.
Dim check As CheckBox = _
CType(Place.FindControl("FeatureCheckBox"), CheckBox)
' Display the appropriate message based on the state of the
' CheckBox control.
If check.Checked Then
Message.Text = "Feature enabled."
Else
Message.Text = "Feature disabled."
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<h3> CheckBox Constructor Example </h3>
Click the check box.
<br><br>
<asp:Placeholder id="Place"
runat="server"/>
<br><br>
<asp:Label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create new CheckBox control.
CheckBox NewCheckBox = new CheckBox();
NewCheckBox.ID="FeatureCheckBox";
NewCheckBox.Text="Enable feature";
NewCheckBox.AutoPostBack = true;
// Register the event-handling method for the CheckedChanged event.
NewCheckBox.CheckedChanged += new EventHandler(this.Check_Change);
// Add the control to the Controls collection of the
// PlaceHolder control.
Place.Controls.Clear();
Place.Controls.Add(NewCheckBox);
}
void Check_Change(Object sender, EventArgs e)
{
// Retrieve the CheckBox control from the PlaceHolder control.
CheckBox check = (CheckBox)Place.FindControl("FeatureCheckBox");
// Display the appropriate message based on the state of the
// CheckBox control.
if(check.Checked)
{
Message.Text = "Feature enabled.";
}
else
{
Message.Text = "Feature disabled.";
}
}
</script>
</head>
<body>
<form runat="server">
<h3> CheckBox Constructor Example </h3>
Click the check box.
<br><br>
<asp:Placeholder id="Place"
runat="server"/>
<br><br>
<asp:Label id="Message"
runat="server"/>
</form>
</body>
</html>
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
CheckBox-Klasse
CheckBox-Member
System.Web.UI.WebControls-Namespace