+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Repeater not holding data after postback.

Repeater not holding data after postback.

2 posts, 0 answered
  1. Michael
    Michael avatar
    5 posts
    Registered:
    09 Oct 2009
    31 Jan 2011
    Link to this post
    Hello,

    I am trying to create a UserControl which will allow the user to dynamically add/remove "items" to the form. This control is dropped into a page through the Sitefinity Admin.  Below is my code for the repeater.

    <asp:Repeater ID="ItemRepeater" runat="server" EnableViewState="true">
        <ItemTemplate>
            <div class="form-field" style="width:525px;">
                <div style="float:right;margin-right:15px;"><asp:LinkButton ID="ItemRemoveButton" runat="server" OnCommand="RemoveItem_Command" CommandArgument='<%# Container.ItemIndex %>' CommandName="Delete" Text="Remove Item" /> </div>
                <div>Item <%# Container.ItemIndex + 2 %></div>
                <div><asp:TextBox ID="ItemTextBox" runat="server" TextMode="MultiLine" Width="505" Height="100" class="item" Text='<%# Eval("Item") %>' /></div>
            </div>
            <div class="form-field" style="width:60px;">
                <div>Price:</div>
                <div>$<asp:TextBox ID="PriceTextBox" runat="server" Width="49" MaxLength="7" class="numeric" Text='<%# Eval("Price") %>' /></div>
            </div>
        </ItemTemplate>
    </asp:Repeater>
     
    <div class="form-field full-width">
        <asp:Button ID="AddItemButton" runat="server" Text="+ Add Another Item" Width="130" OnClick="AddItemButton_Click" />
        <hr />
    </div>

    When when trying to access the Repeater control on the back-end, the repeater has no items in it's collection.  I have tested this same code outside of Sitefinity and accessing the items on the back-end works just fine.

    Could anybody shed some light on this issue?  I have experienced it several times in the past with all dynamically generated controls and I would like to know whats going on.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Feb 2011
    Link to this post
    Hello Michael,

    "When when trying to access the Repeater control on the back-end, the repeater has no items in it's collection"

    How and where do you access the repeater? It is possible that it is too early and the data is still not populates. Could you try .to subscribe for ItemDataBound event and see when it is called and get the DataItem from there?

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered