失落的动态添加点击事件将每个TableCell的每个的TableRow [英] Lost dynamically added click events to each TableCell in each TableRow
问题描述
我开发活表的WebForms
。
我在每一个加入的TableRow这种控制每个TableCell的,当我加入新行到表:
I'm adding such control to each TableCell in each TableRow, when I'm adding new rows to the table:
// in some method, which creates the table
TableRow row = new TableRow();
// here goes other cells with text data
TableCell cellActions = new TableCell();
cellActions.ID = "offerActionsOfferId" + enumerator.Current.offerId;
// init button View More for cell
LinkButton buttonViewExpanded = new LinkButton();
buttonViewExpanded.ID = "buttonViewExpandedOfferId" + enumerator.Current.offerId;
buttonViewExpanded.CssClass = "table-actions-button ic-table-edit";
buttonViewExpanded.Click += new EventHandler(buttonViewExpanded_Click);
buttonViewExpanded.ToolTip = "some alt...";
cellActions.Controls.Add(buttonViewExpanded);
/* end of Action Buttons */
...
row.Cells.Add(cellActions);
this.tableMarket.Controls.Add(row);
但有一种失败与新的EventHandler(buttonViewExpanded_Click)
方法。
表呈现在ASPX页面pretty很好,所有的控制都是可见的,但是当我尝试点击LinkButton的一个都出现故障。
Table renders in the ASPX page pretty well and all controls are visible, but a fail occurs when I try to click that LinkButton.
当我标志着一个断点,并试图抓住我的ASP.NET程序的执行在调试器中做一些分析工作方案 - 在页面刷新仅在Click事件处理程序没有一个断点被抓到。
When I've marked a breakpoint and try to catch the execution of my ASP.NET program in the debugger to make some analyse of program work - the page only refreshed and no one breakpoint in the click event handler has been caught.
为什么会出现这种问题?而如何使其工作?
Why does it occur? And how to make it work?
推荐答案
我不能测试你的code;它关系到其它类,如 InternalApi
。但是,这里是我发现了什么。
I cannot test your code; it ties to other classes like InternalApi
. However, here is what I found.
您需要弄清楚的方式来加载 SetTableBodyForSceneMarket 在页的init 。
You need to figure out the way to load SetTableBodyForSceneMarket in page init.
这基本上就重装后动态创建的控件回;否则,这些控件将为空,并不能触发事件。
It basically reload dynamically created controls on post back; otherwise, those controls will be null, and cannot fire events.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if(IsPostBack)
{
SetTableBodyForSceneMarket();
}
}
private void SetTableBodyForSceneMarket()
{
...
}
这篇关于失落的动态添加点击事件将每个TableCell的每个的TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!