TextBox.AutoPostBack Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy automatyczne ogłaszanie zwrotne na serwerze występuje, gdy kontrolka TextBox traci fokus.

public:
 virtual property bool AutoPostBack { bool get(); void set(bool value); };
public virtual bool AutoPostBack { get; set; }
[System.Web.UI.Themeable(false)]
public virtual bool AutoPostBack { get; set; }
member this.AutoPostBack : bool with get, set
[<System.Web.UI.Themeable(false)>]
member this.AutoPostBack : bool with get, set
Public Overridable Property AutoPostBack As Boolean

Wartość właściwości

Boolean

truejeśli automatyczne ogłaszanie zwrotne występuje, gdy kontrolka TextBox traci fokus; w przeciwnym razie . false Wartość domyślna to false.

Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak za pomocą AutoPostBack właściwości automatycznie wyświetlać sumę wartości wprowadzonych w polach tekstowych, gdy kontrolka TextBox traci fokus.

Ważne

Ten przykład zawiera pole tekstowe, które akceptuje dane wejściowe użytkownika, co jest potencjalnym zagrożeniem bezpieczeństwa. Domyślnie ASP.NET strony sieci Web sprawdzają, czy dane wejściowe użytkownika nie zawierają skryptów ani elementów HTML. Aby uzyskać więcej informacji, zobacz Script Exploits Overview (Omówienie luk w zabezpieczeniach skryptów).

<%@ 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>
    <title> TextBox Example </title>
<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 id="form1" 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>

               &nbsp
 
            </td>

         </tr>

      </table>

   </form>

</body>
</html>
<%@ Page Language="VB" 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>
    <title> TextBox Example </title>
<script runat="server">

      Protected Sub Page_Load(sender As Object, e As EventArgs)
    
         Dim Answer As Integer

         ' 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 Then
 
            Answer = Convert.ToInt32(Value1.Text) + Convert.ToInt32(Value2.Text)

            AnswerMessage.Text = Answer.ToString()

         End If

      End Sub

   </script>

</head>

<body>

   <form id="form1" 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>

               &nbsp
 
            </td>

         </tr>

      </table>

   </form>

</body>
</html>

Uwagi

Użyj właściwości , AutoPostBack aby określić, czy automatyczne ogłaszanie zwrotne na serwerze nastąpi po utracie fokusu TextBox kontrolki. Naciśnięcie klawisza ENTER lub klawisza TAB w kontrolce jest najczęstszym sposobem zmiany fokusu TextBox .

Uwaga

TextBox Jeśli kontener nadrzędny kontrolki zawiera przycisk oznaczony jako przycisk domyślny (na przykład jeśli kontener DefaultButton lub DefaultButton właściwość jest ustawiona), zdarzenie przycisku Click domyślnego nie jest wywoływane w odpowiedzi na automatyczne ogłaszanie zwrotne.

Tej właściwości nie można ustawić za pomocą motywów ani motywów arkusza stylów. Aby uzyskać więcej informacji, zobacz ThemeableAttribute tematy i ASP.NET motywy i skórki.

Dotyczy

Zobacz też