Update Panel and AsyncPostbackTriggers

I would love to add AsyncPostback triggers dynamically to ImageButtons found in 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 can’t figure out how to do this!

I already tried differently, but NONE seems to work.

My last attempt was trying to add triggers to 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 true.

Could you tell me how to add dynamic triggers to UpdatePanel controls?

+3
source share
1 answer

Since your buttons are already inside the update panel, there is no reason to add them dynamically since they still generate async postback.

+1
source

All Articles