Export (0) Print
Expand All

TextBox.AutoPostBack Property

Gets or sets a value indicating whether an automatic post back to the server occurs whenever the user presses the ENTER or the TAB key while in the TextBox control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[ThemeableAttribute(false)] 
public virtual bool AutoPostBack { get; set; }
/** @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.

NoteNote

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.

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">

               &nbsp;

            </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>

               &nbsp
 
            </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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft