开发者

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 fals开发者_开发百科e. 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜