CheckBox.AutoPostBack Property
Gets or sets a value indicating whether the CheckBox state automatically posts back to the server when clicked.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
<asp:CheckBox AutoPostBack="True|False" />
Property Value
Type: System.Booleantrue to automatically post the state of the CheckBox control to the server when it is clicked; otherwise, false. The default is false.
Use this property to specify whether the state of the CheckBox control is posted back to the server when clicked.
Note |
|---|
Setting this property to true causes a round trip to the server every time the control is clicked. |
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.
| Topic | Location |
|---|---|
| How to: Specify Whether ASP.NET Web Server Controls Post to the Server | Building ASP .NET Web Applications |
| How to: Specify Whether ASP.NET Web Server Controls Post to the Server | Building ASP .NET Web Applications |
| Walkthrough: Validating User Input in a Web Forms Page | Building ASP .NET Web Applications in Visual Studio |
The following example demonstrates how to use the AutoPostBack property to automatically post the state of the CheckBox control to the server when the control is clicked.
Note |
|---|
The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model. |
<%@ Page Language="C#" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CheckBox CheckedChanged Example</title> <script runat="server"> 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 = CalculateTotal(checkbox1.Checked).ToString("c"); } void Page_Load(Object sender, EventArgs e) { // Display the subtotal without tax when the page is first loaded. if(!IsPostBack) { // Calculate the subtotal and display the result in currency format. Message.Text = CalculateTotal(false).ToString("c"); } } 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; } </script> </head> <body> <form id="form1" runat="server"> <h3>CheckBox CheckedChanged Example</h3> Select whether to include tax in the subtotal. <br /><br /> <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 id="Message" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:CheckBox id="checkbox1" runat="server" AutoPostBack="True" Text="Include 8.6% sales tax" TextAlign="Right" OnCheckedChanged="Check_Clicked"/> </td> </tr> </table> </form> </body> </html>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note