When Accessing repeater items of repeater in AJAX Updatepanel, it returns wrong values after update
Posted on 2008-10-30
I've got a repeater control within an AJAX update panel. The repeater shows product info and a textbox where the user can insert a quantity to order.
Because there are too many products to show them all, I only show products starting with 'A', and above the repeater links with 'B', 'C', etc. If the user clicks the 'B'-link, the repeater is newly databound with products starting with 'B'. As the repeater is in an updatepanel, this happens without postback as wanted.
This works fine and the Repeater shows the right products. The problem is, that if the user clicks the submit button on the page, i loop through the repeateritems. BUT: the repeater items contain values from the page that was originally loaded; lblID still contains the IDs from the 'A' products instead of the correct ID for the 'B'-products.
What am i doing wrong? How can i access the current values of the repeater items?
In simplified form, the repeater looks like this:
<asp:Repeater ID="rptProducts" runat="server">
<td><asp:Label ID="lblID" runat="server" Visible="false"></asp:Label></td>
<td><asp:TextBox ID="txtQuantity" Columns="1" runat="server" EnableViewState="false"></asp:TextBox></td>
In the button click handler, i'm looping like this:
foreach (RepeaterItem rpi in rptProducts.Items)
TextBox txtQuantity = (TextBox)rpi.FindControl("txtQuantity");
Label lblID = (Label)rpi.FindControl("lblID");