3

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?

OrElse
  • 9,709
  • 39
  • 140
  • 253
  • Your code seems to be OK - at least, it worked for me in C#.. Are you getting any errors? BTW - since your buttons are already inside the update panel there is no reason for adding them dynamically as they generate an async postback anyway. – Denis Ivin Mar 12 '11 at 21:01
  • @Denis Ivin Oh my GOD! I think i need a full time break! Do you mind posting this an an answer? – OrElse Mar 12 '11 at 21:14

1 Answers1

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.

Denis Ivin
  • 5,594
  • 1
  • 26
  • 25