页面中有2个链接按钮,似乎添加了事件处理程序,但日志没有被触发。
protected void Page_Load(object sender, EventArgs e)
{
foreach (var btn in Master.FindControl("ContentPlaceHolder1").Controls.OfType<LinkButton>())
{
btn.Click += new EventHandler(log);
}
}
void log(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
//somecode
}
答案 0 :(得分:0)
答案是;
protected void Page_Load(object sender, EventArgs e)
{
foreach (var btn in Master.FindControl("ContentPlaceHolder1").Controls.OfType<LinkButton>())
{
btn.Click += log;
}
}
void log(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
//somecode
}