簡體   English   中英

列表框OnSelectedIndexChanged不起作用

[英]Listbox OnSelectedIndexChanged doesn't work

我的jQuery對話框中有一個列表框,

<div id="dialog">
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:ListBox ID="lbxTitle" runat="server" style="width:400px;height:100px;" OnSelectedIndexChanged="lbxTitle_SelectedIndexChanged">
    <asp:ListItem value="2" Text="abc" />
    <asp:ListItem value="3" Text="def" />
</asp:ListBox>
<br />
<fieldset>
    <asp:Label ID="lblContent" runat="server" style="height:200px;" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>

在后面的代碼中,我有這個功能

protected void lbxTitle_SelectedIndexChanged(object sender, EventArgs e)
{
   lblContent.Text = "test";
}

我不放置autopostback =“ true”,因為它將刷新整個頁面並關閉對話框。

如何使用戶單擊列表框上的項目時,它將在對話框內的標簽上顯示“測試”。

現在,如果我更改所選項目,它什么也不做。

您應該放置自動回發,然后才能使用AsyncPostBack防止整個頁面回發...

按照以下代碼

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:ListBox ID="lbxTitle" runat="server" style="width:400px;height:100px;" OnSelectedIndexChanged="lbxTitle_SelectedIndexChanged" AutoPostBack="true">
                <asp:ListItem value="2" Text="abc" />
                <asp:ListItem value="3" Text="def" />
            </asp:ListBox>
            <br />
            <fieldset><asp:Label ID="lblContent" runat="server" style="height:200px;" />
            </fieldset>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="lbxTitle" />
        </Triggers>
    </asp:UpdatePanel>

添加自動回發,並在創建對話框后將其移回表單:

$("#dialog").parent().appendTo($("form:first"));

嘗試這個:

<script type="text/javascript">

    $(function() {
        <% if (Page.IsPostback) { %>
            $('id of your listbox').change();
        <% } %>
    });

</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM