Web Server Controls->ASP.NET CheckBox Control
Definition and Usage
The CheckBox control is used to display a check box.
Properties
| Property | Description |
|---|---|
| AutoPostBack | A Boolean value that specifies whether the form should be posted immediately after the Checked property has changed or not. Default is false |
| Checked | A Boolean value that specifies whether the check box is checked or not |
| id | A unique id for the control |
| OnCheckedChanged | The name of the function to be executed when the Checked property has changed |
| runat | Specifies that the control is a server control. Must be set to "server" |
| Text | The text next to the check box |
| TextAlign | On which side of the check box the text should appear (right or left) |
Examples
Checkbox
ASPX Source:
| <script runat="server"> Sub Check(sender As Object, e As EventArgs) if check1.Checked then work.Text=home.Text else work.Text="" end if End Sub </script> <html> <body> <form runat="server"> <p>Home Phone: <asp:TextBox id="home" runat="server" /> <br /> Work Phone: <asp:TextBox id="work" runat="server" /> <asp:CheckBox id="check1" Text="Same as home phone" TextAlign="Right" AutoPostBack="True" OnCheckedChanged="Check" runat="server" /> </p> </form> </body> </html> |
Output Result:
|
Home Phone: |
In this example we declare two TextBox controls and one CheckBox control in an .aspx file. Then we create an event handler for the CheckedChanged event to copy the contents of a text box containing the home phone of a customer into a text box that contains the work phone.
浙公网安备 33010602011771号