Webユーザーコントロール(ascx2)を含むWebユーザーコントロール(ascx1)があります。そのascx2の中にはdataListがあります。
ASCX1:
Page_Load
{
var bp = (Mbp)Page.LoadControl(<b>ASCX2</b>);
bp.dataSource = new List<...> { ... };
placeholder.Controls.Add(bp);
}
ASCX2
public List<TBusiness> dataSource;
private static List<...> ds;
private static ITemplate itemTemplate;
private static ITemplate editTemplate;
Page_Load
{
...
if (!this.IsPostBack)
{
ds = this.dataSource;
itemTemplate = new CustomTemplate(...);
editTemplate = new CustomTemplate(...);
}
dataList.ItemTemplate = itemTemplate;
dataList.EditItemTemplate = editTemplate;
dataList.DataSource = ds;
dataList.DataBind();
}
ItemTemplate
ImageButton {CommmandName="Edit"}
protected void dataList_EditCommand(object source, DataListCommandEventArgs e)
{
dataList.EditItemIndex = e.Item.ItemIndex;
dataList.DataBind();
}
EditTemplate:
ImageButton {CommmandName="Delete"}
ImageButton {CommmandName="Cancel"}
ImageButton {CommmandName="Update"}
問題:クリックImageButton{CommmandName="Edit"}
すると、テンプレートをEditTemplateに変更します。要素を編集できますが、EditTemplateのImageButtonイベント(削除、キャンセル、更新)は無視されます。これらのImagebuttonをクリックしても何も起こらず、itemTemplateに戻るだけです。これらのImageButton(削除、キャンセル、更新)のイベントをキャッチできません。