Populer Topics

CheckBox Control

This control is used to accept the choice from user. It is used to display multiple choice from which user can select one or many Item from choice.

The Checkbox control support following property.

Property Description
Text

Enable us to set Text to the Checkbox..

TextAlign

Enable us to align the Checkbox control text.

Checked

Enable us to get or set weather the Checkbox control is Clicked or Checked.

CausesValidation Specifies if a page is validate when Checkbox is Clicked.
ValidationGroup Group Of Control for which the Checkbox control causesValidation, When it is postback to the server
AutoPostback Automatically postback to server when checkbox is click.

 

.Aspx File

	<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" 
        Inherits="Codeplanex.WebForm1" %>

	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head runat="server">
	    <title></title>
	    <style type="text/css">
	        .style1 {
	            text-decoration: underline;
	        }
	    </style>
	</head>
	<body>
	    <form id="form1" runat="server">
	        <asp:CheckBox ID="chkCricket" AutoPostBack="true" runat="server" Checked="true"
                Text="Cricket" OnCheckedChanged="chkCricket_CheckedChanged" />
	        <asp:CheckBox ID="chkHocky" runat="server" AutoPostBack="true" Checked="true" 
                Text="Hocky" OnCheckedChanged="chkHocky_CheckedChanged" />
	        <br /><br />
	        <asp:Label ID="lblHobby" runat="server" Text="" />
	    </form>
	</body>
	</html>

.Cs File

protected void chkHocky_CheckedChanged(object sender, EventArgs e)
{
    lblHobby.Text = "Your Hobby Is : " + chkHocky.Text;
}

protected void chkCricket_CheckedChanged(object sender, EventArgs e)
{
     lblHobby.Text = "Your Hobby Is : " + chkCricket.Text;
}