【发布时间】:2016-08-24 03:11:15
【问题描述】:
现在我有一个方法可以根据搜索栏中的输入动态生成信息表,每行都有一个按钮。按下时,该按钮应该获取其所在行中的信息并对其进行处理。
我的问题是我的按钮没有做任何事情,但我不确定如何修复它。即使尝试在 VS 中发布到输出面板也不起作用。一旦我按下一个,它所做的就是清除我所有的值 - 我表中的所有内容 - 通过刷新页面全部恢复为默认值。
// The bottom section of the method which 'generates' buttons for each row made in the for loop - everything works perfect to this point
TableCell addButtonCell = new TableCell();
Button addButton = new Button();
addButton.Text = "Add";
addButton.Width = 75;
addButton.Click += new EventHandler(addButton_Click);
addButtonCell.Controls.Add(addButton);
row.Cells.Add(addButtonCell);
tblResults.Rows.Add(row);
}
// button event handler
public void addButton_Click(object sender, EventArgs e) {
System.Diagnostics.Debug.Write("TESTING!!!!!"); // Tried this, no effect
}
【问题讨论】:
-
你期待什么?如果您的页面令人耳目一新,我相信您的按钮按预期工作。加上你在点击事件中的过程都会显示在VS的输出窗口中。
-
我不认为有办法阻止它重新加载页面但仍然执行代码,是吗?我试图用处理程序做其他事情 - 但当然,它令人耳目一新,所以无论如何它都被擦除了。
-
使用更新面板避免刷新。
-
你找到答案了吗?
-
我没有。不幸的是,提出的解决方案都不适用于我的情况,所以我不得不改变设计 - 但我让它适用于新设计。