This documentation is archived and is not being maintained.

HtmlInputCheckBox Server Control Declarative Syntax

Creates a server-side control that maps to the <input type=checkbox> HTML element and allows you to a create check box control that lets the user select a true or false state.

    OnDataBinding="OnDataBinding event handler"
    OnDisposed="OnDisposed event handler"
    OnInit="OnInit event handler"
    OnLoad="OnLoad event handler"
    OnPreRender="OnPreRender event handler"
    OnServerChange="OnServerChange event handler"
    OnUnload="OnUnload event handler"

Use the HtmlInputCheckBox control to program against the <input type=checkbox> HTML element. The HtmlInputCheckBox control does not post back to the server when it is clicked. The state of the check box is sent to the server for processing when you use a control that posts back the server, such as the HtmlInputButton control. To determine whether the check box is selected, test the Checked property of the control.


This control does not require a closing tag.

The following example demonstrates how to create an HtmlInputCheckBox control that allows the user to select a true or false state. When a user clicks the input button included on the page, the Button1_Click event handler determines whether the HtmlInputCheckBox control is checked. It then displays a message in a <span> control. Note that even though the checked value is set to true by default in this example, the user still needs to click Button1 to display the text.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
<title>HtmlInputCheckBox Control</title>

    <script runat="server">
       void Button1_Click(object Source, EventArgs e) 
          if (Check1.Checked == true) 
             Span1.InnerHtml = "Check1 is checked!";
             Span1.InnerHtml = "Check1 is not checked!";


    <h3>HtmlInputCheckBox Sample</h3>

    <form id="Form1" runat="server">
        <input id="Check1" type="checkbox" runat="server" checked="checked"/> 
            CheckBox1 &nbsp;&nbsp;
        <span id="Span1" style="color:red" runat="server" />
        <br />
        <input type="button" id="Button1" value="Enter"
               onserverclick="Button1_Click" runat="server"/>