Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A control with ID could not be found for the trigger in UpdatePanel

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?

like image 275
Dismissile Avatar asked Jul 12 '11 16:07

Dismissile


People also ask

What is trigger in UpdatePanel?

Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their AutoPostBack property set to true.

What is postback trigger in UpdatePanel?

AsyncPostBackTrigger - use these triggers to specify a control within or outside of the UpdatePanel that, when clicked, should trigger a partial page postback. PostBackTrigger - use these triggers to have a control within the UpdatePanel cause a full page postback rather than a partial page postback.

Can we use update panel in MVC?

With MVC you are rendering your Html stream much more directly than the abstracted/pseudo-stateful box that WebForms wraps you up in. Of course UpdatePanel can be used in much more complex scenarios than this (it can contain INPUTS, supports ViewState and triggers across different panels and other controls).


1 Answers

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 :)

like image 179
Muhammad Akhtar Avatar answered Oct 06 '22 19:10

Muhammad Akhtar