9

I have an update panel that has UpdateMode of Conditional and ChildrenAsTriggers set to false. I only want a few controls to cause an asynchronous postback:

<asp:UpdatePanel ID="updPnlMain" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>

      // ...
      <asp:Repeater ID="rptListData" runat="server">
          <ItemTemplate>
              <asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
          </ItemTemplate>
      </asp:Repeater>
      // ...
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnAddSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

I am getting the following error when I try and load this page:

A control with ID 'btnAddSomething' could not be found for the trigger in UpdatePanel 'updPnlMain'.

Since my btnAddSomething control is in a repeater and might not be there right away it acts like it is nonexistent. How can I get around this?

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
Dismissile
  • 32,564
  • 38
  • 174
  • 263

1 Answers1

13

Because your control is in the repeater control and it is out of scope to the Trigger collection. By the way you don't need to add trigger because your button control is already in the UpdatePanel, it will update when you click the button.

Edit: There is a solution if you really want to update your updPnlMain updatepanel. You can put in another updatepanel and put your button in that panel. e.g.

<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
  <asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ContentTemplate>

and then simply call the updPnlMain.Update(); method in btnAddSomething_Click event.

It will actually do what you are looking for :)

Off The Gold
  • 1,228
  • 15
  • 28
Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
  • 1
    Not if ChildrenAsTriggers=false...which is what I said in the question. – Dismissile Jul 12 '11 at 16:17
  • How can I get my repeater controls children to be in the scope then? – Dismissile Jul 12 '11 at 16:18
  • You only want to update your UpdatePanel updPnlMain, onclick of button ? – Muhammad Akhtar Jul 12 '11 at 16:19
  • I want a few triggers. One of them is outside of the UpdatePanel. The other is the btnAddSomething button that is inside of the repeater. It is actually a LinkButton with the Command event in my real scenario however. I tried setting ChildrenAsTriggers="true" so I didn't have to specify the Triggers manually but even then the link button wasn't causing an async postback. – Dismissile Jul 12 '11 at 16:21
  • http://stackoverflow.com/questions/30352866/how-to-prevent-full-page-postback-on-selectedindexchange-for-dropdownlist I don't know why my page is doing a full postback. Please help. – SearchForKnowledge May 20 '15 at 15:26