.NET Framework Class Library
ListControl.AutoPostBack Property

Gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection.

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

Syntax

Visual Basic (Declaration)
<ThemeableAttribute(False)> _
Public Overridable Property AutoPostBack As Boolean
Visual Basic (Usage)
Dim instance As ListControl
Dim value As Boolean

value = instance.AutoPostBack

instance.AutoPostBack = value
C#
[ThemeableAttribute(false)] 
public virtual bool AutoPostBack { get; set; }
C++
[ThemeableAttribute(false)] 
public:
virtual property bool AutoPostBack {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_AutoPostBack ()

/** @property */
public void set_AutoPostBack (boolean value)
JScript
public function get AutoPostBack () : boolean

public function set AutoPostBack (value : boolean)

Property Value

true if a postback to the server automatically occurs whenever the user changes the selection of the list; otherwise, false. The default is false.
Remarks

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. For more information, see ThemeableAttribute and ASP.NET Themes and Skins Overview.

Example

The following example demonstrates how to enable AutoPostBack for the ListBox control.

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <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 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>
 
C#
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <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 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>
 
JScript
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

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

   </script>

</head>

<body>

   <form 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>
 
Platforms

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.

Version Information

.NET Framework

Supported in: 2.0, 1.1, 1.0
See Also

Tags :


Page view tracker