我使用下面LinkButton
的代码添加代码,但是当我点击每个链接按钮时,点击事件不会调用,但如果我删除if(!IsPostBack)
工作正常
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.sr();
}//if
}
void sr()
{
LinkButton lnk;
for (int i =1; i < 6; i++)
{
lnk = new LinkButton();
lnk.ID="lnk"+i.ToString();
lnk.Text = i.ToString() + " ";
lnk.Click += new EventHandler(lnk_Click);
this.pnl.Controls.Add(lnk);
}
}
void lnk_Click(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
lnk.Text = "Clicked";
}