动态添加按钮,怎样让事件正确响应?
sbwgi 2004-03-02 10:57:22 我在日历控件中动态添加了Button按钮(最开始是用LinkButton,可LinkButton连点都不能点),可是在客户端点击按钮时,好象没响应事件,应该怎样才能让事件正确响应呢?
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;
if (d.IsOtherMonth)
{
c.Controls.Clear();
c.BackColor=System.Drawing.Color.White;
return;
}
DateTime oTime=d.Date;
//如果日志不为空
if(this.GetLogDetail(oTime)!="")
{
//LinkButton oLButton=new LinkButton();
//oLButton.Text=this.GetLogDetail(oTime);
//oLButton.Visible=true;
//oLButton.Click+=new EventHandler(oLButton_Click);
Button oButton=new Button();
oButton.Text=this.GetLogDetail(oTime);
oButton.Visible=true;
oButton.Click+=new EventHandler(oButton_Click);
oButton.Command+=new CommandEventHandler(oButton_Command);
c.Controls.Add(oButton);
}
}
private void oButton_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
this.ImageButton1.Visible=true;
this.ImageButton2.Visible=true;
this.FreeTextBox1.Visible=true;
}
private void oButton_Command(object sender, CommandEventArgs e)
{
this.ImageButton1.Visible=true;
this.ImageButton2.Visible=true;
this.FreeTextBox1.Visible=true;
}