New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Getting Started with the Telerik WebForms CheckBox
The following tutorial demonstrates how to set up a page with a RadCheckBox control and use its OnCheckedChanged server event:
- In the default page of a new ASP.NET AJAX-enabled Web Application add a RadCheckBox control:
ASPX
<telerik:RadCheckBox ID="RadCheckBox1" runat="server" />
- Set the
Text
,Value
andCommandArgument
properties:
ASPX
<telerik:RadCheckBox ID="RadCheckBox1" runat="server" Text="Some Text" Value="0" CommandArgument="arg1" />
- To hook to the OnCheckedChanged server-side event of RadCheckBox add an attribute to the main control tag and add the method signature:
ASPX
<telerik:RadCheckBox ID="RadCheckBox1" runat="server" OnCheckedChanged="RadCheckBox1_CheckedChanged" Text="Some Text" Value="0" CommandArgument="arg1" />
C#
protected void RadCheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
- Add a Label control to write the information to:
ASPX
<asp:Label ID="Label1" Text="" runat="server" />
- Use the CheckedChanged event handler to write information about the checkbox properties:
C#
protected void RadCheckBox1_CheckedChanged(object sender, EventArgs e)
{
RadCheckBox checkbox = sender as RadCheckBox;
string data = string.Format("current text: {0}, current value {1}, current command argument: {2}, checked: {3}",
checkbox.Text, checkbox.Value, checkbox.CommandArgument, checkbox.Checked);
Label1.Text = data;
}