[英]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.