不触发按钮点击事件动态 [英] not firing button click event dynamically

查看:95
本文介绍了不触发按钮点击事件动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

iam动态创建按钮并生成点击事件

实际上,我的功能是根据服务(数量)创建按钮并生成点击事件
我在这里创建了全球对象.

按钮是基于计数创建的,但是当我单击按钮click事件时不会触发.

但这不是解雇让我知道任何问题.

hi all

iam creating a button dynamically and generate click event

actually my functionality is creating button based on services(count) and generate click event
here im creating gloabally object.

buttons are creating based on count but when i click the button click event not firing.

but it''s not firing let me know any issue.

//global
private Button BtnServices;

//button creating for loop
       BtnServices = new Button();
       BtnServices.Text = "Click Me";
       BtnServices.Click += new EventHandler(BtnServices_Click);

void BtnServices_Click(object sender, EventArgs e)
    {
          Label1.Text="Hi...";
    }

推荐答案

尝试一下:
Try this:
BtnServices = new Button();
BtnServices.ID = "BtnServices";
BtnServices.Text = "Click Me";
BtnServices.Click += new System.EventHandler(BtnServices_Click);

void BtnServices_Click(object sender, EventArgs e)
    {
          Label1.Text="Hi...";
    }


看看以下解决方案链接:
http://stackoverflow.com/questions/8324585/dynamically-created-button- not-firing-click-event [ ^ ]
http://stackoverflow.com/questions/7164628/dynamically-created-button- click-event-not-firing [ ^ ]
http://aspsnippets.com/Articles/Creating-Dynamic- Button-LinkBut​​ton-and-ImageButton-in-ASP.Net.aspx [
Have a look at following links for solution:
http://stackoverflow.com/questions/8324585/dynamically-created-button-not-firing-click-event[^]
http://stackoverflow.com/questions/7164628/dynamically-created-button-click-event-not-firing[^]
http://aspsnippets.com/Articles/Creating-Dynamic-Button-LinkButton-and-ImageButton-in-ASP.Net.aspx[^]




仅分配一个代表,该事件就不会触发.您必须调用委托.

您必须将此按钮呈现到aspx页面,必须处理视图状态,然后当用户单击按钮时,事件将触发.

如果您不渲染按钮,用户将如何单击它.
如果您不渲染按钮,并且想要该功能,则可以像这样调用该函数.

Hi,

Just by assigning a delegate, the event will not fire. You must invoke the delegate.

you must render this button to the aspx page, you must handle the view state, then when user clicks on the button, then the event will fire.

if you are not rendering the button, how user will click on it..??

if you are not rendering the button and if you want that functinality, just call that function like this.

BtnServices_Click(BtnServices, new EventArgs();



祝您编码愉快.



Happy Coding.


这篇关于不触发按钮点击事件动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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