更新面板和 AsyncPostbackTriggers
我很想将 AsyncPostback 触发器动态添加到 UpdatePanel 控件中找到的 ImageButtons
<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers></Triggers>
<ContentTemplate>
<asp:ListView ID="ListView2" runat="server">
<ItemTemplate>
<asp:ImageButton ID="btnRemove" runat="server" ImageUrl="~/Images/Delete.png" CommandName='<%# DataBinder.Eval(Container.DataItem, "QuestionsID") %>'/>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
问题是我不知道如何做到这一点!
我已经尝试过不同的方法,但似乎都不起作用。
我的最后一次尝试是尝试在 ListView ItemDataBound 事件中添加触发器,
Private Sub ListView2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView2.ItemDataBound
For Each btnError As ImageButton In e.Item.Controls.OfType(Of ImageButton)()
Select Case btnError.ID
Case "btnRemove"
Dim trigger As New AsyncPostBackTrigger()
trigger.ControlID = UpdatePanel1.FindControl(btnError.ID).UniqueID
UpdatePanel1.Triggers.Add(trigger)
End Select
Next
End Sub
这当然是不正确的。
那么您能告诉我如何向 UpdatePanel 控件添加动态触发器吗?
I would love to add AsyncPostback Triggers dynamically to the ImageButtons found within the UpdatePanel control
<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers></Triggers>
<ContentTemplate>
<asp:ListView ID="ListView2" runat="server">
<ItemTemplate>
<asp:ImageButton ID="btnRemove" runat="server" ImageUrl="~/Images/Delete.png" CommandName='<%# DataBinder.Eval(Container.DataItem, "QuestionsID") %>'/>
</ItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
The problem is that i cannot figure out how to do it!
I already tried different ways, but NONE seems to work.
My last try, was trying to add the triggers in the ListView ItemDataBound event
Private Sub ListView2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView2.ItemDataBound
For Each btnError As ImageButton In e.Item.Controls.OfType(Of ImageButton)()
Select Case btnError.ID
Case "btnRemove"
Dim trigger As New AsyncPostBackTrigger()
trigger.ControlID = UpdatePanel1.FindControl(btnError.ID).UniqueID
UpdatePanel1.Triggers.Add(trigger)
End Select
Next
End Sub
which of course is not correct.
So could you please tell me how can i add dynamically triggers to the UpdatePanel controls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的按钮已经位于更新面板内,因此没有理由动态添加它们,因为它们无论如何都会生成异步回发。
Since your buttons are already inside the update panel there is no reason for adding them dynamically as they generate an async postback anyway.