0
我需要生成一個動態列表的按鈕,我已經做了,附加了一個事件處理程序。動態生成的按鈕,點擊不被執行
但是,事件處理程序沒有被執行。
private void GetOptions(EcoBonusRequest request)
{
var ecobonuswworkflow = WorkflowFactory.CreateEcobonusWorkflow();
ecobonuswworkflow.SetCurrentStep(request.CurrentStatus);
var currentoptions = ecobonuswworkflow.GetCurrentOptions();
foreach(var option in currentoptions)
{
var btn = new Button() {Text = option.OptionName};
btn.Click +=new EventHandler(btn_Click);
Buttons.Controls.Add(btn);
}
}
void btn_Click(object sender, EventArgs e)
{
var btn = (Button) sender;
string command = btn.Text;
EcoBonusRequest request = this.GetDBRequest(RequestBaseId.Value);
EcoBonusRequestBL.AddWorkflowHistoryItem(request, command,CurrentUser, command);
}
您需要在每次回發時重新創建這些按鈕(具有與之前相同的ID並且最晚在page_load中)。閱讀(特別是第3部分)[真正理解動態控制](http://tinyurl.com/yfc66o) –
你會如何重構這個? –
說實話,如果可能的話,我會只使用[網絡數據綁定控件](http://msdn.microsoft.com/zh-cn/library/ms228214.aspx)像中繼器。 –