HtmlInputCheckBox Class
Allows programmatic access to the HTML <input type= checkbox> element on the server.
For a list of all members of this type, see HtmlInputCheckBox Members.
System.Object
System.Web.UI.Control
System.Web.UI.HtmlControls.HtmlControl
System.Web.UI.HtmlControls.HtmlInputControl
System.Web.UI.HtmlControls.HtmlInputCheckBox
[Visual Basic] Public Class HtmlInputCheckBox Inherits HtmlInputControl Implements IPostBackDataHandler [C#] public class HtmlInputCheckBox : HtmlInputControl, IPostBackDataHandler [C++] public __gc class HtmlInputCheckBox : public HtmlInputControl, IPostBackDataHandler [JScript] public class HtmlInputCheckBox extends HtmlInputControl implements IPostBackDataHandler
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
Use the HtmlInputCheckBox control to allow the user to select a true or false state. To determine whether the control is selected, use the Checked property. The HtmlInputCheckBox control provides a ServerChange event that is raised when the Checked property changes values between posts to the server. This allows you to create an event handler that performs a custom set of instructions each time the event is raised.
Note The HtmlInputCheckBox control does not post back to the server when it is clicked. You must provide another control on the Web page that supports posting to the server, such as an HtmlButton control, to send the state of the control back to the server.
For a list of initial property values for an instance of HtmlInputCheckBox, see the HtmlInputCheckBox constructor.
Example
[Visual Basic, JScript] The following example demonstrates a set of simple responses to users selecting from a group of HtmlInputCheckBox controls.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <script language="VB" runat=server> Sub SubmitBtn_Click (Source As Object, ByVal E as EventArgs) If (Basketball.Checked = true) Then ' You like basketball End If If (Football.Checked = true) Then ' You like football End If If (Soccer.Checked = true) Then ' You like soccer End If End Sub </script> <body> <form method=post runat=server> Enter Interests: <input id="Basketball" checked type=checkbox runat=server> Basketball <input id="Football" type=checkbox runat=server> Football <input id="Soccer" type=checkbox runat="server"> Soccer <input type=button value="Enter" OnServerClick="SubmitBtn_Click" runat=server> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <script language="JSCRIPT" runat=server> function SubmitBtn_Click (source : Object, e : EventArgs){ if(Basketball.Checked == true){ // You like basketball } if(Football.Checked == true){ // You like football } if(Soccer.Checked == true){ // You like basketball } } </script> <body> <form method=post runat=server> Enter Interests: <input id="Basketball" checked type=checkbox runat=server> Basketball <input id="Football" type=checkbox runat=server> Football <input id="Soccer" type=checkbox runat="server"> Soccer <input type=button value="Enter" OnServerClick="SubmitBtn_Click" runat=server> </form> </body> </html>
[C#, C++] No example is available for C# or C++. To view a Visual Basic or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Web.UI.HtmlControls
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
HtmlInputCheckBox Members | System.Web.UI.HtmlControls Namespace