NoteHeaderDiv
Button を含むカスタム複合コントロールがあります。
//NoteHeaderControl snippet
public event EventHandler OnEditClick;
protected void btnEdit_Click(object sender, EventArgs e)
{
if (OnEditClick != null)
{
OnEditClick(sender, e);
}
}
public NoteHeaderControl()
{
this.noteHeaderDiv = new HtmlGenericControl("div");
this.noteHeaderDiv.ID = "noteHeaderDiv";
this.noteHeaderDiv.Attributes.Add("class", "noteHeaderDiv");
this.imagePlaceHolder = new HtmlGenericControl("span");
this.imagePlaceHolder.ID = "imagePlaceHolder";
this.imagePlaceHolder.Attributes.Add("class", "noteCollapsed");
this.lblNoteDate = new Label();
this.lblNoteDate.ID = "lblNoteDate";
this.lblNoteDate.CssClass = "noteDate";
this.lblNoteTitle = new Label();
this.lblNoteTitle.ID = "lblNoteTitle";
this.lblNoteTitle.CssClass = "noteTitle";
this.lblNoteAuthorName = new Label();
this.lblNoteAuthorName.ID = "lblNoteTitle";
this.lblNoteAuthorName.CssClass = "noteAuthor";
this.editButton = new Button();
this.editButton.CssClass = "editNoteButton";
this.editButton.ToolTip = "Editovat";
this.editButton.ID = "editButton";
this.editButton.OnClientClick = "showEditDialog('editPerson');";
this.editButton.Click += btnEdit_Click;
this.addTeamTaskButton = new HtmlGenericControl("button");
this.addTeamTaskButton.ID = "addTeamTaskButton";
this.addTeamTaskButton.Attributes.Add("class", "addTeamTaskButton");
this.addTeamTaskButton.Attributes.Add("onclick", "showDialog('editPerson');");
this.addTeamTaskButton.Attributes.Add("title", "Nový Team Task");
}
#region protected override void CreateChildControls()
protected override void CreateChildControls()
{
base.CreateChildControls();
this.lblNoteDate.Text = String.Format("{0}.{1}.", this.noteDate.Day, this.noteDate.Month);
this.lblNoteTitle.Text = noteTitle;
this.lblNoteAuthorName.Text = noteAuthorName;
//this.editButton.Click += btnEdit_Click;
this.noteHeaderDiv.Controls.Add(imagePlaceHolder);
this.noteHeaderDiv.Controls.Add(lblNoteDate);
this.noteHeaderDiv.Controls.Add(lblNoteTitle);
this.noteHeaderDiv.Controls.Add(lblNoteAuthorName);
this.noteHeaderDiv.Controls.Add(editButton);
this.noteHeaderDiv.Controls.Add(addTeamTaskButton);
this.Controls.Add(noteHeaderDiv);
}
protected override void OnInit(EventArgs e)
{
CreateChildControls();
base.OnInit(e);
}
次にPage_Load
、パブリック イベントを別のハンドラに接続します。問題は、btnEdit_Click
決して発火しないことです。my で動的にボタンを作成し、Page_Load
それを my で定義されたイベント ハンドラーに直接接続するとPage
、すべてが期待どおりに機能します。
それを機能させる方法について何か提案はありますか?私は何が間違っているのか途方に暮れています。