ListControl.AutoPostBack 属性

定义

获取或设置一个值,该值指示当用户更改列表中的选定内容时是否自动产生向服务器的回发。Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection.

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

属性值

如果只要用户更改列表中的选定内容就自动产生向服务器的回发,则为 true;否则为 falsetrue if a postback to the server automatically occurs whenever the user changes the selection of the list; otherwise, false. 默认值为 falseThe default is false.

属性

示例

下面的示例演示如何AutoPostBack ListBox为控件启用。The following example demonstrates how to enable AutoPostBack for the ListBox control.

<%@ 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>ListBox AutoPostBack Example</title>
<script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {
         if (ListBox1.SelectedItem != null)
            Label1.Text = "You selected: " + ListBox1.SelectedItem.Value;
         else
            Label1.Text = "";
      }

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3>ListBox AutoPostBack Example</h3>

      Select an item from the list box: <br /><br />

      <asp:ListBox id="ListBox1" 
           Rows="4"
           AutoPostBack="True" 
           SelectionMode="Single"  
           runat="server">
 
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>
  
      </asp:ListBox>

      <br /><br />

      <asp:Label id="Label1"
           runat="server"/>

   </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 runat="server">
    <title>ListBox AutoPostBack Example</title>
<script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)
      
         If Not IsNothing(ListBox1.SelectedItem)
            Label1.Text = "You selected: " & ListBox1.SelectedItem.Value
         Else
            Label1.Text = ""
         End If

      End Sub

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3>ListBox AutoPostBack Example</h3>

      Select an item from the list box: <br /><br />

      <asp:ListBox id="ListBox1" 
           Rows="4"
           AutoPostBack="True" 
           SelectionMode="Single"  
           runat="server">
 
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>
  
      </asp:ListBox>

      <br /><br />

      <asp:Label id="Label1"
           runat="server"/>

   </form>

</body>
</html>
 

注解

如果服务器需要在true进行选择时立即捕获所选内容,请将此属性设置为。Set this property to true if the server needs to capture the selection as soon as it is made. 例如,可以根据用户在列表控件中所做的选择,自动填充网页上的其他控件。For example, other controls on the Web page can be automatically filled depending on the user's selection from a list control.

此属性可用于根据用户在列表中所做的选择,自动填充网页上的其他控件。This property can be used to allow automatic population of other controls on the Web page based on a user's selection from a list.

此属性的值存储在视图状态中。The value of this property is stored in view state.

无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请ThemeableAttribute参阅和ASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

适用于