Why is the ASP.NET Repeater.Items collection empty, when controls are on the screen?

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-02-24T12:39:21Z Indexed on 2010/04/03 6:13 UTC
Read the original article Hit count: 298

Filed under:
|

I have an ASP page with the following repeater:

<asp:Repeater runat="server" ID="RegionRepeater"
    DataSourceID="SqlDataSourceRegions" EnableViewState="true">
    <ItemTemplate>
        <tr>
            <td valign="top">
                <b><%#Eval("description")%></b>
                <asp:HiddenField runat="server" ID="RegionID"
                    Value='<%#Eval("region_id")%>'/>
            </td>
            <td>
                <asp:FileUpload ID="FileUpload" runat="server" Width="368px" />
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

(The repeater is inside a Wizard, inside a content pane).

The code behind is connected to the

protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)

event. There are two items on the screen (two rows inside the table). However, when the code tries to read those items, the Items collection is empty!

foreach(RepeaterItem region in RegionRepeater.Items)
{
    // Never runs - the RegionRepeater.Items.Count = 0
    FileUpload fileUpload = (FileUpload) region.FindControl("FileUpload");
    String regionID = ((HiddenField)region.FindControl("RegionID")).Value;
    ...

Why is the collection empty, when there are controls drawn on the screen?

Thanks a lot for any help; this is starting to drive me nuts.

(BTW: I tried adding/removing the EnableViewState="true" tag)

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about repeater