Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update panel and AsyncPostbackTriggers

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?

like image 507
OrElse Avatar asked Jun 07 '26 12:06

OrElse


1 Answers

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

like image 129
Denis Ivin Avatar answered Jun 09 '26 02:06

Denis Ivin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!