更新面板和 AsyncPostbackTriggers

发布于 2024-10-21 18:25:46 字数 1486 浏览 0 评论 0原文

我很想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韵柒 2024-10-28 18:25:46

由于您的按钮已经位于更新面板内,因此没有理由动态添加它们,因为它们无论如何都会生成异步回发。

Since your buttons are already inside the update panel there is no reason for adding them dynamically as they generate an async postback anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文