ASP:按钮的Click事件不会被解雇 [英] asp:Button Click event not being fired

查看:92
本文介绍了ASP:按钮的Click事件不会被解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态的ASP表中添加行。在该表的每一行,我也包括具有SelectProduct_Click事件的按钮。

I am dynamically adding rows in an asp table. In each row of the table I am also including a button which has a SelectProduct_Click event.

问题是,即使我注册单击事件,是不是被解雇的事件。

The problem is that even though I am registering the click event, the event is not being fired.

该按钮以这种方式被添加

The button is being added in this way:

btnSelect = new Button();
btnSelect.ID = "btnSelect";
btnSelect.CommandArgument = od.ProductId;
btnSelect.Click += new EventHandler(this.SelectProduct_Click);
btnSelect.CssClass = "button";
btnSelect.Text = "Select";
cell = new TableCell();
cell.Controls.Add(btnSelect);
row.Cells.Add(cell);

我怎样才能让我的按钮发射的点击?

How can I get my button to fire on click?

推荐答案

您需要了解的 ASP.NET页面生命周期

为了动态控制火上回发他们的活动,他们需要再次重新创建并连接到事件处理程序。

In order for dynamic controls to fire their events on postback, they need to be recreated and attached to the event handler again.

创建(并重新创建)动态控制的最佳位置是在的OnInit 事件处理程序。

The best place to create (and re-create) dynamic controls is in the OnInit event handler.

这篇关于ASP:按钮的Click事件不会被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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