This documentation is archived and is not being maintained.
CheckBox Constructor
.NET Framework 1.1
Initializes a new instance of the CheckBox class.
[Visual Basic] Public Sub New() [C#] public CheckBox(); [C++] public: CheckBox(); [JScript] public function CheckBox();
Remarks
Use this constructor to create and initialize a new instance of the CheckBox class.
Example
[Visual Basic] <%@ 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> [C#] <%@ 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>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
CheckBox Class | CheckBox Members | System.Web.UI.WebControls Namespace
Show: