TextBox.AutoPostBack Property
Assembly: System.Web (in system.web.dll)
/** @property */ public boolean get_AutoPostBack () /** @property */ public void set_AutoPostBack (boolean value)
public function get AutoPostBack () : boolean public function set AutoPostBack (value : boolean)
Property Value
true if an automatic post back to the server occurs whenever the user presses the ENTER or the TAB key while in the TextBox control; otherwise, false. The default is false.Use the AutoPostBack property to specify whether an automatic post back to the server will occur whenever the user presses the ENTER or the TAB key while in the TextBox control.
Note |
|---|
| A postback occurs only when the user presses the ENTER or the TAB key while in the TextBox control. |
This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.
| Topic | Location |
|---|---|
| How to: Respond to Changes in a TextBox Web Server Control | Building ASP .NET Web Applications |
| How to: Specify Whether ASP.NET Web Server Controls Post to the Server | Building ASP .NET Web Applications |
| How to: Respond to Changes in a TextBox Web Server Control | Building ASP .NET Web Applications |
| How to: Specify Whether ASP.NET Web Server Controls Post to the Server | Building ASP .NET Web Applications |
The following code example demonstrates how to use the AutoPostBack property to automatically display the sum of the values entered in the text boxes when the user presses the ENTER or the TAB key.
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> protected void Page_Load(Object sender, EventArgs e) { int Answer; // Due to a timing issue with when page validation occurs, call the // Validate method to ensure that the values on the page are valid. Page.Validate(); // Add the values in the text boxes if the page is valid. if(Page.IsValid) { Answer = Convert.ToInt32(Value1.Text) + Convert.ToInt32(Value2.Text); AnswerMessage.Text = Answer.ToString(); } } </script> </head> <body> <form runat="server"> <h3> TextBox Example </h3> <table> <tr> <td colspan="5"> Enter integer values into the text boxes. <br> The two values are automatically added <br> when you tab out of the text boxes. <br> </td> </tr> <tr> <td colspan="5"> </td> </tr> <tr align="center"> <td> <asp:TextBox ID="Value1" Columns="2" MaxLength="3" AutoPostBack="True" Text="1" runat="server"/> </td> <td> + </td> <td> <asp:TextBox ID="Value2" Columns="2" MaxLength="3" AutoPostBack="True" Text="1" runat="server"/> </td> <td> = </td> <td> <asp:Label ID="AnswerMessage" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:RequiredFieldValidator ID="Value1RequiredValidator" ControlToValidate="Value1" ErrorMessage="Please enter a value.<br>" EnableClientScript="False" Display="Dynamic" runat="server"/> <asp:RangeValidator ID="Value1RangeValidator" ControlToValidate="Value1" Type="Integer" MinimumValue="1" MaximumValue="100" ErrorMessage="Please enter an integer <br> between than 1 and 100.<br>" EnableClientScript="False" Display="Dynamic" runat="server"/> </td> <td colspan="2"> <asp:RequiredFieldValidator ID="Value2RequiredValidator" ControlToValidate="Value2" ErrorMessage="Please enter a value.<br>" EnableClientScript="False" Display="Dynamic" runat="server"/> <asp:RangeValidator ID="Value2RangeValidator" ControlToValidate="Value2" Type="Integer" MinimumValue="1" MaximumValue="100" ErrorMessage="Please enter an integer <br> between than 1 and 100.<br>" EnableClientScript="False" Display="Dynamic" runat="server"/> </td> <td>   </td </tr> </table> </form> </body> </html>
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note