ListControl.AutoPostBack Property (System.Web.UI.WebControls)

Switch View :
ScriptFree
.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
<ThemeableAttribute(False)> _
Public Overridable Property AutoPostBack As Boolean
C#
[ThemeableAttribute(false)]
public virtual bool AutoPostBack { get; set; }
Visual C++
[ThemeableAttribute(false)]
public:
virtual property bool AutoPostBack {
	bool get ();
	void set (bool value);
}
F#
[<ThemeableAttribute(false)>]
abstract AutoPostBack : bool with get, set
[<ThemeableAttribute(false)>]
override AutoPostBack : bool with get, set
ASP.NET
<asp:ListControl AutoPostBack="True|False" />

Property Value

Type: System.Boolean
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.

Examples

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

Visual Basic


<%@ 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>
 


C#

<%@ 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>
 


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Community Content

Dillon Bergkamp
Default (GenreSelector + ListView met alles) | Labo3
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="_2deEx_WT3_Labo03.web._Default" %>
    <%@ Register Src="~/wuc/wucGenreSelector.ascx" TagName="GenreSelector" TagPrefix="uc2" %>
    <%@ Register Src="~/wuc/wucMovieEdit.ascx" TagName="MovieEdit" TagPrefix="uc" %>


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">


<uc2:GenreSelector id="genreSelector2" runat="server"/>

    <br />
    <asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1">
    <LayoutTemplate>
                <div><asp:PlaceHolder ID="ItemPlaceHolder" runat="server" /> </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div>
                    <asp:LinkButton ID="LinkButton" runat="server" CommandName="select"><%# Eval("Title")%> (<%# Eval("Year")%>)</asp:LinkButton>
                </div>
            </ItemTemplate>
                        <SelectedItemTemplate>

                <div>
                    <h3><%# Eval("Title")%> (<%# Eval("Year")%>)</h3>
<%--                    <p>Genre: <%# GetGenreName(Eval("Genre"))%></p>--%>
                    <p><%# Eval("Plot")%></p>
                    <asp:Button ID="Button1" runat="server" Text="Edit" commandName="edit"/>
                    <asp:Button ID="Button2" runat="server" Text="Delete" CommandName="delete" />
                </div>
            </SelectedItemTemplate>
            <InsertItemTemplate>
                <br /><uc:MovieEdit ID="movieInsert" runat="server" Title='<%#Bind("Title")%>' Year='<%#Bind("Year")%>' Plot='<%#Bind("Plot") %>' Genre='<%#Bind("Genre") %>'/>
                <asp:Button ID="btnInsert" runat="server" Text="Insert" CommandName="insert" ValidationGroup="movie-edit" />
            </InsertItemTemplate>
            <EditItemTemplate>
                <uc:MovieEdit ID="movieEdit" runat="server" Title='<%#Bind("Title")%>' Year='<%#Bind("Year")%>' Plot='<%#Bind("Plot") %>' Genre='<%#Bind("Genre") %>'/>
                <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="update" ValidationGroup="movie-edit"/>
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="cancel"/>
            </EditItemTemplate>
    </asp:ListView>
    <br />
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetMovies" TypeName="_2deEx_WT3_Labo03.bl.Movie"
        DataObjectTypeName="_2deEx_WT3_Labo03.bl.Movie" DeleteMethod="DeleteMovie"
        InsertMethod="InsertMovie" UpdateMethod="UpdateMovie">

            <SelectParameters>
                <asp:ControlParameter ControlID="genreSelector2" Name="genre"
                    PropertyName="GenreId" Type="String" />
            </SelectParameters>

    </asp:ObjectDataSource>

    <br />

    </asp:Content>

Dillon Bergkamp
Default | Labo2
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="herexWT3week2._Default" %>

<%@ Register src="WUC/wucTerritory.ascx" tagname="wucTerritory" tagprefix="uc1" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <div>
    
        <uc1:wucTerritory ID="wucTerritory1" runat="server" />
    
        <asp:BulletedList ID="blEmployees" runat="server" DataSourceID="odsEmployees"
            AppendDataBoundItems="True" DataTextField="Firstname" DataValueField="Id">
        </asp:BulletedList>

            <asp:ObjectDataSource ID="odsEmployees" runat="server"
        SelectMethod="GetEmployees" TypeName="herexWT3week2.BL.Employee">
        <SelectParameters>
            <asp:ControlParameter ControlID="wucTerritory1" DefaultValue="" Name="territory"
                PropertyName="TerritoryID" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
        

    </div>



</asp:Content>

Dillon Bergkamp
Default (codebehind) | Labo2
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If wucTerritory1.IsPostBack = True Then
            blEmployees.Items.Clear()
        End If
    End Sub

End Class