views:

213

answers:

0

I have a usercontrol (Imageselector.ascx) that consists of a datalist. The datalist's itemtemplate contains another usercontrol (selectoricon.ascx) that contains an imagebutton. In default.aspx page i include the Imageselector.ascx and populate its datalist from db with DataBind(). In the datalist's onItemdataBound event I populate the selectoricons with data.

To maintain control state i store controls' properties in viewstate.

All works fine, the controls fires events etc. But I need to include a button (for paging) in default.aspx that causes postback. On this postback I want to reload data from the database and repopulate the datalist, so i use the button's onClick event. Here i load new data and bind it to datalist again:

DataTable tbl = GetNewData();
sel.IconDataSource = tbl;
sel.imgPathField = "imgpath";
sel.iconIDField = "id";
sel.DataBind();

The problem is that the selectoricons are empty after postback. In debugger I checked that the datalist has the correct number of items, the onItemDataBound event is called, the selectoricons are assigned correct values during onItemDataBound, but they sow up empty. If I comment out the sel.DataBind() row above, the icons are not empty, so their values are restored from viewstate. But the databind during onclick event makes them empty.

I have an impression that after i populate the datalist, it is being reset by something. Maybe I am populating the datalist in wrong point of lifecycle? But how to repopulate them then on button click?