ListControl.AutoPostBack プロパティ

定義

リストの選択を変更したときに、サーバーへのポストバックが自動的に発生するかどうかを示す値を取得または設定します。

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

プロパティ値

リストの選択を変更するたびにサーバーへのポストバックが自動的に発生する場合は true、それ以外の場合は false。 既定値は、false です。

属性

次の例では、 コントロールに対して を有効にする AutoPostBack 方法を ListBox 示します。

<%@ 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 設定します。 たとえば、リスト コントロールからのユーザーの選択に応じて、Web ページ上の他のコントロールを自動的に入力できます。

このプロパティを使用すると、リストからのユーザーの選択に基づいて、Web ページ上の他のコントロールを自動的に作成できます。

このプロパティの値はビューステートに格納されます。

このプロパティは、テーマまたはスタイル シート テーマによって設定することはできません。 詳細については、「テーマとスキン」と「ASP.NET」を参照してくださいThemeableAttribute

適用対象