Besides the ID and the runat="server" attributes, probably the most important visual characteristics of a check box is its check mark. When it is checked, the control has a value of true. Otherwise, its value is false. To support this, the asp:CheckBox is equipped with an attribute named Checked whose values can be True or False. When designing the form, if you want the check box to display a checked mark, add the Checked attribute and assign the desired value. Here is an example: <%@ Page Language="C#" %> <html> <head> <title>Altair Real Estate</title> </head> <body> <h3>Altair Real Estate</h3> <p> <form id="frmRealEstate" method="post" runat="server"> <asp:CheckBox id="chkHasCarGarage" style="left: 20px" runat="server" Checked="True" text="Has Car Garage"></asp:CheckBox> </form> </p> </body> </html> When using a check box, the user is supposed to check or uncheck it by clicking it. This action changes the state of the control. When the user clicks a check box, the control changes its state and fires an event called CheckedChanged. This event is implemented by the EventArgs class. In other words, the class that implements it doesn't give any other information than to let you know that the control has been clicked. To visually implement this event, click the control on the form and, in the Events section of the Properties window, double-click CheckedChange. This event is handled by the OnCheckedChanged attribute. To manually implement this event, create a method that is passed an Object and an EventArgs arguments. In the asp:CheckBox tag, add the OnCheckedChanged attribute and assign the name of the method to it. Here is an example: <%@ Page Language="C#" %> <html> <head> <script runat="server"> private void CheckBoxWasClicked(Object sender, EventArgs e) { } </script> <title>Altair Real Estate</title> </head> <body> <h3>Altair Real Estate</h3> <p> <form id="frmRealEstate" method="post" runat="server"> <asp:CheckBox id="chkHasCarGarage" style="left: 20px" runat="server" Checked="True" OnCheckedChanged="CheckBoxWasClicked" text="Has Car Garage"></asp:CheckBox> </form> </p> </body> </html>
As its appearance suggests, a check box invites a visitor to click the control. When this has been done, you can indicate whether the should post the result to the server. To support this, the asp:CheckBox tag is equipped with a Boolean attribute named AutoPostBack. Its default value is "False". If you want to change it, type this attribute and assign "True" to it. This would be done as follows: <asp:CheckBox id="chkHasCarGarage" AutoPostBack="True" style="left: 20px" runat="server" Checked="True" text="Has Car Garage"></asp:CheckBox> |
|
|||||
|