后台生成的控件,如何添加事件?
vb.net中写:
Response.Write("<asp:linkbutton ID='LinkButton1' runat='server' onclick=''>" & "文件下载地址" & "</asp:LinkButton>" & vbCrLf)
如何添加LinkButton1的 LinkButton1_Click事件呢?
[解决办法]
同意ls说法~
C#写法,希望对你有所提示
protected void Page_Load(object sender, EventArgs e) { LinkButton btn = new LinkButton(); btn.ID = "btnshow"; btn.Text = "click me"; btn.Click += new EventHandler(btn_Click); } void btn_Click(object sender, EventArgs e) { //your click event method }
[解决办法]
Page.Controls.Add(btn);