Search code examples
vb.netupdatepanelrepeaterscriptmanager

A control with ID could not be found for the trigger in UpdatePanel- COMMAND ARGUMENT WORKAROUND


Here's an update panel with triggers:

<asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="true">
   <ContentTemplate>
      <p> Much wow! </p>
   </ContentTemplate>
   <Triggers>
   <asp:AsyncPostBackTrigger ControlID='x' EventName="Command" />
   </Triggers>
</asp:UpdatePanel>

This is my repeater (NOT INSIDE THE UPDATE PANEL):

<asp:Repeater ID="Repeater1" runat="server">
   <ItemTemplate>
     <asp:LinkButton ID="x" OnCommand="x_command" runat="server" CommandArgument='<%#Eval("y") %>'>
   </ItemTemplate>
</asp:Repeater>

I am unable to find the controlID of the linkbutton. I've tried registering the control, the control gets registered but the updatepanel still cannot find the control.

Code to register control-

Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
   Dim lb As LinkButton = TryCast(e.Item.FindControl("dude1"), LinkButton)
   ScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(lb)
   Response.Write("afa")
End Sub

Solution

  • I just realized- all I didn't have to do was define the button as trigger in the update panel. When you register it as an asyncpostback control, it already acts as a trigger.

    Hope this helps anyone that got stuck.