dr.Xis
dr.Xis

Reputation: 127

trigger an async postback for an update panel from a repeater control

I have an ASP.NET Repeater Control inside an UpdatePanel. I need to update another control when clicking in an ImageButton (inside of the Repeater template). The thing is that I can't get that to trigger.

The panel upPanelRotator is refreshed... which I don't want...I just want to call back to server to update another panel - which I'll control from the server.

Any ideas?

<asp:UpdatePanel ID="upPanelRotator" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Repeater ID="rptRotator" runat="server" OnItemCommand="rptRotator_ItemCommand">
            <ItemTemplate>
                <asp:ImageButton ID='imgBtn' runat="server" />
        </asp:Repeater>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="ItemCommand" />
    </Triggers>
</asp:UpdatePanel>

Upvotes: 0

Views: 11755

Answers (3)

sMs
sMs

Reputation: 121

I have right now similar situation, and I have do this so that I wrap control inside Repeater in another UpdatePanel, and I set AutoPostBack="true" of that control, and register

< asp:AsyncPostBackTrigger ControlID="imgBtn" EventName="Click"/ >

my only consideration on this is how will a such number of UpdatePanels reflect upon performance. I have small project with few DB entry's but for larger amounts of Data, I would test performance before and after such intervention.

Upvotes: 0

Chad H
Chad H

Reputation: 594

You should be able to add an async postback trigger to the updatepanel you want to update. Set the control id of the repeater and the "ItemCommand" event as the event name... like this:

<asp:UpdatePanel ID="updatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="repeaterId" EventName="ItemCommand" />
    </Triggers>
    <ContentTemplate>

...

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

If PanelA has the trigger button, and you want to update PanelB, you would need to have the async postback trigger on the UpdatePanel surrounding PanelB. The problem is, you need to give the actual ID's of the buttons, which specifying imgButton like you have above won't work (because there could be many in the repeater, and async trigger requires one reference that it won't be able to find). To make this very simpe, wrap everything in the UpdatePanel, and that will make your life easier. Otherwise, you have to add the async postback triggers from code I believe.

Upvotes: 0

Related Questions