我已经从代码后面创建了链接按钮,并使用这样的动作绑定 但是这个方法Render永远不会在click事件上调用。我错过了什么?
Panel pnlMain = new Panel();
Panel pnlContent = new Panel();
LinkButton lbContent = new LinkButton();
lbContent.Click += new EventHandler(Redirect);
pnlContent.Controls.Add(lbContent);
pnlMain.Controls.Add(pnlContent);
private void Redirect(object sender, EventArgs e)
{
}
答案 0 :(得分:0)
试试这个,
Panel pnlMain = new Panel();
Panel pnlContent = new Panel();
LinkButton lbContent = new LinkButton();
lbContent.Click += new EventHandler(Redirect);
Redirect(this, EventArgs.Empty);
private void Redirect(object sender, EventArgs e)
{
}
答案 1 :(得分:0)
你是否缺少runat ="服务器"标签?然而,编纂者应该抱怨这一点。
试试这个它会起作用。
在您的aspx页面
<form id="form1" runat="server">
<div>
</div>
</form>
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
Panel pnlMain = new Panel();
Panel pnlContent = new Panel();
LinkButton lbContent = new LinkButton();
lbContent.Text = "click";
lbContent.Click += new EventHandler(Redirect);
pnlContent.Controls.Add(lbContent);
pnlMain.Controls.Add(pnlContent);
this.form1.Controls.Add(pnlMain);
}
private void Redirect(object sender, EventArgs e)
{
}