Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

ListControl.AutoPostBack Property

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

[Visual Basic]
Public Overridable Property AutoPostBack As Boolean
[C#]
public virtual bool AutoPostBack {get; set;}
[C++]
public: __property virtual bool get_AutoPostBack();
public: __property virtual void set_AutoPostBack(bool);
[JScript]
public function get AutoPostBack() : Boolean;
public function set AutoPostBack(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.

Example

[Visual Basic, C#, JScript] 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>
 

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ListControl Class | ListControl Members | System.Web.UI.WebControls Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.