Hello
I have a repeater that is looping a user control, like this:
<asp:Repeater ID="repItems" runat="server" EnableViewState="false"
OnItemCommand="repItems_ItemCommand">
<ItemTemplate>
<dmg:confirmItem runat="server"
OnDataBinding="confirmitemItem_DataBinding"
Basket="<%# Container.DataItem %>" />
</ItemTemplate>
</asp:Repeater>
My code behind looks like this:
public void BindItems(List<ShopBasket> baskets)
{
_baskets = baskets;
repItems.DataSource = baskets;
repItems.DataBind();
}
My custom user control looks like this:
public ShopBasket Basket;
protected void Page_Load(object sender, EventArgs e)
{
imgItem.ImageUrl = ShopImagePath + Basket.ImageFilename;
...etc...
}
All works brilliantly the first time around, the basket items are bound to Basket objects and everything is great.
However, when I receive an ItemCommand from my repeater, and update the basket contents (Note: No adding or removing is done here, just updates the quantity) then I rebind to see the latest values, and BOOM! Null reference - no Basket object in the user control Page_Load. This is despite tracing through to see that the BindItems() method is called as usual, and the Baskets are there.
I presume this has something to do with the life cycle but it has me beat.
Any ideas?
Thanks Duncan