CheckBox
CheckBox CheckedChanged Example
Select whether to include tax in the subtotal.
Shopping cart | |
---|---|
Item 1 | $1.99 |
Item 2 | $2.99 |
Item 3 | $3.99 |
Subtotal | TWD8.97 |
@inherits ControlComponent
<p>Select whether to include tax in the subtotal.</p>
<table border="1" cellpadding="5">
<tr>
<th colspan="2">
Shopping cart
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
$1.99
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
$2.99
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
$3.99
</td>
</tr>
<tr>
<td>
<b>Subtotal</b>
</td>
<td>
<asp.Label @ref="this.message" Text="@this.CalculateTotal(false).ToString("c")" />
</td>
</tr>
<tr>
<td colspan="2">
<asp.CheckBox @ref="this.checkbox"
AutoPostBack="true"
Text="Include 8.6% sales tax"
TextAlign="TextAlign.Right"
OnCheckedChanged="this.Check_Clicked" />
</td>
</tr>
</table>
@code {
private Label message;
private CheckBox checkbox;
protected void Check_Clicked(object sender, EventArgs e)
{
// Calculate the subtotal and display the result in currency format.
// Include tax if the check box is selected.
message.Text = this.CalculateTotal(checkbox.Checked).ToString("c");
}
protected double CalculateTotal(bool taxable)
{
// Calculate the subtotal for the example.
double result = 1.99 + 2.99 + 3.99;
// Add tax, if applicable.
if (taxable)
{
result += result * 0.086;
}
return result;
}
}
CheckBox Toggle Switch Example
@inherits ControlComponent
<asp.CheckBox ID="Switch1" _ref="() => this.toggleCheckBox"
AutoPostBack="true"
OnCheckedChanged="this.CheckBox_CheckedChanged">Toggle this custom switch element</asp.CheckBox>
<br />
<asp.Label @ref="this.message" />
@code {
private ToggleCheckBox toggleCheckBox = new ToggleCheckBox();
private Label message;
protected void CheckBox_CheckedChanged(object sender, EventArgs e)
{
message.Text = $"checked is {toggleCheckBox.Checked}";
}
public class ToggleCheckBox : CheckBox
{
protected override void OnInit(EventArgs e)
{
this.LabelMode = LabelMode.For;
//bootstrap toggle switch css.
this.CssClass = "custom-control custom-switch";
this.InputAttributes["class"] = "custom-control-input";
this.LabelAttributes["class"] = "custom-control-label";
base.OnInit(e);
}
}
}
CheckBox Metadata
Name | Type | Kind |
---|---|---|
AccessKey | String | Parameter |
Attributes | IReadOnlyDictionary | Parameter |
AutoPostBack | Boolean | Parameter |
BackColor | String | Parameter |
BorderColor | String | Parameter |
BorderStyle | BorderStyle | Parameter |
BorderWidth | String | Parameter |
CausesValidation | Boolean | Parameter |
Checked | Boolean | Parameter |
ClientIDMode | ClientIDMode | Parameter |
CssClass | String | Parameter |
Enabled | Boolean | Parameter |
FontBold | Boolean | Parameter |
FontItalic | Boolean | Parameter |
FontNames | String | Parameter |
FontOverline | Boolean | Parameter |
FontSize | String | Parameter |
FontStrikeout | Boolean | Parameter |
FontUnderline | Boolean | Parameter |
ForeColor | String | Parameter |
Height | String | Parameter |
ID | String | Parameter |
LabelMode | LabelMode | Parameter |
Style | String | Parameter |
TabIndex | Int16 | Parameter |
Text | String | Parameter |
TextAlign | TextAlign | Parameter |
ToolTip | String | Parameter |
ValidationGroup | String | Parameter |
Visible | Boolean | Parameter |
Width | String | Parameter |
OnCheckedChanged | EventHandler | Event |
OnDataBinding | EventHandler | Event |
OnDisposed | EventHandler | Event |
OnInit | EventHandler | Event |
OnLoad | EventHandler | Event |
OnPreRender | EventHandler | Event |
OnUnload | EventHandler | Event |