我们如何在运行时创建按钮上生成事件? [英] How we generate a event on run time created button?

查看:65
本文介绍了我们如何在运行时创建按钮上生成事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在运行时创建的按钮上生成事件?

How we generate a event on run time created button???

推荐答案

哪种编程语言?

对于c#:

Which programminglanguage?

For c# :

Button x = new Button();
x.Click += new EventHandler(x_Click);



单击该按钮时,将执行以下方法:



When the button is clicked, the following method is executed :

private void x_Click(object sender, EventArgs e)
{
    // Button clicked
}



希望对您有帮助!

爱德华



Hope it helps!

Eduard




用户遵循的方式.

Hi,

User following way.

Button btn = new Button();
btn.Click += 



在上面的代码中,执行+ =后,您将看到选项卡的工具提示消息.



In above code after doing += you will see tooltip message for tab.


尝试此操作

公共局部类TempFunction:System.Web.UI.Page
{
TextBox txt =新的TextBox();
Button btn = new Button();
标签lbl = new Label();
受保护的void Page_Load(对象发送者,EventArgs e)
{

lbl.Text =输入文字:";
lbl.Font.Bold = true;

this.Form.Controls.Add(lbl);
this.Form.Controls.Add(txt);
txt.Text ="Hello World";
btn.Text ="btnsave";
btn.Attributes.Add("runat","server");
this.Form.Controls.Add(btn);
btn.Click + = new System.EventHandler(this.Button_Click);
}

受保护的void Button_Click(对象发送者,EventArgs e)
{
txt.Text =更改";
}
try this

public partial class TempFunction : System.Web.UI.Page
{
TextBox txt = new TextBox();
Button btn = new Button();
Label lbl = new Label();
protected void Page_Load(object sender, EventArgs e)
{

lbl.Text = "Enter Text : ";
lbl.Font.Bold = true;

this.Form.Controls.Add(lbl);
this.Form.Controls.Add(txt);
txt.Text = "Hello World";
btn.Text = "btnsave";
btn.Attributes.Add("runat", "server");
this.Form.Controls.Add(btn);
btn.Click += new System.EventHandler(this.Button_Click);
}

protected void Button_Click(object sender, EventArgs e)
{
txt.Text = "Change";
}


这篇关于我们如何在运行时创建按钮上生成事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆