aspxtreme

CheckBox Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Creates a check box control that allows the user to switch between a true or false state.

Declarative Syntax

NOTE: The content of an <asp:CheckBox> control can be defined within its opening tag. In this case, you can close the start tag with a trailing slash /> instead of using a separate end tag.

For information on the individual members of this class, see CheckBox in the class library.

Remarks

The CheckBox control displays a check box that allows users to switch between a true or false state.

Use the Checked property to specify or determine whether the CheckBox control is checked. The CheckedChanged event is raised when the form is posted to the server and the state of the CheckBox control changed from the previous post. You can provide an event handler for the CheckedChanged event to customize the actions performed when the state of the CheckBox control changes between posts to the server.

NOTE: When creating multiple CheckBox controls, you can also use the CheckBoxList control. The CheckBoxList control is easier to use for creating a set of check boxes using data binding, while the individual CheckBox control gives you greater control over layout.

Syntax Example

The following shows a sample declaration for a CheckBox control in an .aspx file. The check box is set to immediately post the form back to the server when it is checked.

<asp:checkbox id="myCheckBox" runat="server" autopostback />

The following example demonstrates how you can dynamically change the Text property of a CheckBox control depending on whether it is checked or not.

void Page_Load ( Object src, EventArgs e ) {
   myLink.Visible = myCheckBox.Checked ? true : false;
   myCheckBox.Text = myLink.Visible ? "Uncheck to Hide Text Link" : "Show Text Link";
}
  C# VB
Dynamic CheckBox Sample
Run Sample   View Source
See Also

CheckBox Class   CheckBox and CheckBoxList Web Server Controls



Books and more ...


Suggested Reading

Need a break ?



Previous page Back to top Next page

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support aspxtreme