ListControl.AutoPostBack Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau menetapkan nilai yang menunjukkan apakah postback ke server secara otomatis terjadi ketika pengguna mengubah pilihan daftar.
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
Nilai Properti
true
jika postback ke server secara otomatis terjadi setiap kali pengguna mengubah pilihan daftar; jika tidak, false
. Default adalah false
.
- Atribut
Contoh
Contoh berikut menunjukkan cara mengaktifkan AutoPostBackListBox kontrol.
<%@ 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>
Keterangan
Atur properti ini ke true
jika server perlu mengambil pilihan segera setelah dibuat. Misalnya, kontrol lain di halaman Web dapat diisi secara otomatis tergantung pada pilihan pengguna dari kontrol daftar.
Properti ini dapat digunakan untuk memperbolehkan populasi otomatis kontrol lain pada halaman Web berdasarkan pilihan pengguna dari daftar.
Nilai properti ini disimpan dalam status tampilan.
Properti ini tidak dapat diatur oleh tema atau tema lembar gaya. Untuk informasi selengkapnya, lihat ThemeableAttribute dan ASP.NET Tema dan Kulit.