<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
<table width="100%" cellpadding="2" cellspacing="0">
<tr valign="top" class="ArticleTitle">
<td style="padding-left:10px;" valign="middle">
asp:CheckBox control</td>
</tr>
<tr>
<td class="ArticleContents">
CheckBox control is used to give option to the user.
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
<div class="ArticleContents">
Ideally CheckBox control is used to give option to the user. When it is rendered on the page, it is implemented through <input type=checkbox></input> HTML tag.
Its properties like <span class="DemoCP">BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. </span>
are implemented through style properites of <input>.
You can set its Text property either by setting Text properties in the .aspx page or from server side page. (other properties can also be set from both pages)
<p> </p>
Following are some important properties that are very useful.
<table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
<tr>
<td class="DemoCP">AutoPostBack</td>
<td>
Form is automatically posted back when CheckBox is checked or Unchecked.
</td>
</tr>
<tr>
<td class="DemoCP">CausesValidation</td>
<td>
true/false. If true, Form is validated if Validation control has been used in the form.
</td>
</tr>
<tr>
<td class="DemoCP">Checked</td>
<td>
true/false. If true, Check box is checked by default.
</td>
</tr>
<tr>
<td class="DemoCP">OnCheckedChanged</td>
<td>
Fires when CheckBox is checked or Unchecked. This works only if <span class="DemoCP">AutoPostBack</span> property is set to true.
</td>
</tr>
<tr valign="Top">
<td class="DemoCP">ValidationGroup</td>
<td>
Used to put a checkbox under a particular validation group. It is used when you have many set of form controls and by clicking a paricular button
you want to validate a particular set of controls only.
</td>
</tr>
</table>
<!-- START - Demo Section -->
<table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
<tr>
<td class="DemoTitle">
DEMO : CheckBox
</td>
<td align="right">
<a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/checkbox.aspx" target="_blank">Show Source Code</a>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Home Address"></asp:Label>
<asp:TextBox ID="TextBox1" runat="Server"></asp:TextBox>
<asp:RequiredFieldValidator ID="req1" runat="server" Text="Please write home address." ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" AssociatedControlID="TextBox2" runat="Server" Text="Office Address"></asp:Label>
<asp:TextBox ID="TextBox2" runat="Server"></asp:TextBox>
<asp:CheckBox ID="checkbox1" runat="Server" Text="Click, if Office address is same as Home address" AutoPostBack="True" OnCheckedChanged="PutHomeAddressAsOfficeAddress" BorderColor="brown" BorderWidth="1" CausesValidation="True" />
</td>
<td>
Ex. <asp:Label ID="Label1" runat="server" BackColor="Coral" ForeColor="blue" BorderColor="ActiveBorder" BorderStyle="dashed" BorderWidth="1" Height="20" Text="Example of Label Control" Width="200" ></asp:Label>
</td>
</tr>
<tr>
<td colspan="2">
<!-- START - Server Side Code -->
<pre>
// CheckBox control
<asp:CheckBox ID="checkbox2" runat="Server" Text="Click, if Office address is same as Home address" AutoPostBack="True" OnCheckedChanged="PutHomeAddressAsOfficeAddress" BorderColor="brown" BorderWidth="1" CausesValidation="True" />
// Fires when CheckBox is clicked(checked) or unchecked
protected void PutHomeAddressAsOfficeAddress(object sender, EventArgs e)
{
if (checkbox1.Checked)
{
TextBox2.Text = TextBox1.Text;
Label1.Text = "Notice: Home address has been written into Office TextBox too.";
}
else
{
TextBox2.Text = "";
Label1.Text = "Notice: Office address is empty now.";
}
}
</pre>
<!-- END - Server Side Code -->
</td>
</tr>
</table>
<!-- END - Demo Section -->
</div>
<br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>
Go Top