动态添加按钮,怎样让事件正确响应?

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;

}
...全文
71 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧