[英]CheckBoxList AJAX async postback issue
我有2个CheckBoxList控件-chk1和chk2。 如果选择了另一个,我需要使用异步回发来清除CheckBoxList的选择。 以下内容将不会清除chk1,如果它具有选择,并且已检查项目chk2:
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1" />
<asp:AsyncPostBackTrigger ControlID="chk2" />
</Triggers>
<ContentTemplate>
<asp:Label ID="result" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" OnDataBound="assignClickBehaviours" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>
后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
processChecks();
}
private void processChecks()
{
if(chk2.SelectedIndex>-1)
chk1.ClearSelection();
}
如果将整个内容都放在了更新面板中,它将可以工作...但是由于复选框中可以包含150个项目,因此如果选择了底部的项目,则在上溢:自动上的滚动将弹回到顶部。 我需要滚动状态保持不变(因此需要异步回发)。 有什么想法或选择吗?
您可以尝试此代码..
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1">
</asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="chk1">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>
</form></body>
请尝试使用此代码,
processChecks();
请进行以下更改,请注意EventName'SelectedIndexChanged'
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="chk2" EventName="SelectedIndexChanged"/>
</Triggers>
<ContentTemplate>
<asp:Label ID="result" runat="server" />
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.