Advertisements

Archive

Posts Tagged ‘postback from repeater control with updatepanel’

UpdatePanel and triggers from a repeater control


If you want to backstop on some controls click you must need to specify triggers in UpdatePanel

For example:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
   <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
     <ItemTemplate>
       <%# Eval("Name") >%>
       <asp:Button ID="Button1" runat="server" Text="Button" />
      </ItemTemplate>
    </asp:Repeater>
 </ContentTemplate>
<Triggers>
   <asp:PostBackTrigger ControlID="Buton1" />
</Triggers>
</asp:UpdatePanel>

You will face following error message with above code

A control with ID ‘Button1’ could not be found for the trigger in UpdatePanel ‘UpdatePanel1’.

Here is simple solution for above problem

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
  <ItemTemplate>
 <!--when cick the button1, it will fire the btnDummy-->
   <asp:Button ID="Button1" Text="Click"
   OnClientClick="$get('btnDummy').click();return false;"
   runat="server" />
  </ItemTemplate>
 </asp:Repeater>

 <!--Make a hidden button to treat as the postback trigger-->
 <asp:Button ID="btnDummy" runat="server" Style="display: none" Text="HiddenButton" />
Advertisements