单击中继器中的复选框列表时刷新页面
我对更新面板中的中继器控制这样的问题感到恼火。
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
我面临的问题是,每当我从下拉列表中选择任何值时,所有页面都会刷新。在谷歌上花了几个小时后,我找到了一个解决方案,即在中继器的 itemdatabound 事件上,我们只需要在找到下拉列表后添加以下代码,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
它非常有效对于下拉列表来说很好,但对于复选框列表同样不起作用,就像使用 scripmanager 实例一样,如果我编写 sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits)
,它不起作用:(
I am annoyed with a problem I have repeater control in updatepanel like this.
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The problem I face that whenever I select any value from dropdown all the page gets refreshed After spending hours on the google I found a solution i.e, on itemdatabound event of repeater we just need to add the following code after finding the dropdown,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
It worked very well for the dropdown but same is not working for checkboxlist like using the scripmanager instance if I write sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits)
, it is not working :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
ClientIDMode="AutoID"
添加到 Repeater 控件。您不必添加任何触发器,甚至不必调用
RegisterAsyncPostBackControl
。ChildrenAsTriggers
应该处理这个问题。Add
ClientIDMode="AutoID"
to the Repeater control.You should not have to add any triggers and you should not even have to call
RegisterAsyncPostBackControl
. TheChildrenAsTriggers
should take care of that.在 Repeater ItemDataBound 事件上
使用 screiptmanager 方法 RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" 将您的复选框 ID 放在这里"));
on Repeater ItemDataBound event
use screiptmanager method RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" put here your checkbox ID "));
在
开始之前添加以下内容:Add this Before start of
<ContentTemplate>
: