何时使用AutopostBack

AutopostBack是通常在Dropdownlist,Radiobuttonlist,ListBox控件中使用的属性。

您将使用此控件显示一组项目,

当您单击列表中的项目时,选定的索引已更改

事件将被触发。无论如何,默认情况下,没有任何反应

这个事件。

如果您要执行某项操作,则应使autopostback =“ True”。因此,每当事件触发时,

需要将数据回传,您将使用此方法。

这是自动回传的示例。

源代码:

<body>
    <form id="form1" runat="server">
    <div>
    <asp:ListBox ID="lb1" Rows="4" runat="server" AutoPostBack="true" >
    <asp:ListItem>India</asp:ListItem>
    <asp:ListItem>Southafrica</asp:ListItem>
    <asp:ListItem>Australia</asp:ListItem>
    <asp:ListItem>England</asp:ListItem>  
    </asp:ListBox>
    <br />
    <br />
    <asp:Label ID="lab1" runat="server">
    </asp:Label>
    </div>
    </form>
</body>  
后面的代码:
protected void Page_Load(object sender, EventArgs e)
        { 
        } 
        protected void lb1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lb1.SelectedItem != null)
            {
                lab1.Text = "you selected" + lb1.SelectedItem.Value;
            }
            else
            {
                lab1.Text = "";
            } 
        } 
注意:您也可以在Page_load事件中编写该代码...

From: https://bytes.com/topic/net/insights/940055-when-use-autopostback

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值