Background:我正在定制现有的ASP.NET/C#应用程序.它有自己的小"框架"和约定,供开发人员在扩展/定制其功能时遵循.我目前正在扩展它的一些管理功能,框架为其提供了一个契约,以强制实现返回System.Web.UI.Control
的GetAdministrationInterface()
方法.在托管GUI界面的页面的Page_Load()
方法期间调用此方法.
Problem:我的GUI中有三个按钮,每个按钮都分配了一个事件处理程序.我的管理GUI加载得非常好,但是单击任何一个按钮都不会执行我期望它们执行的操作.但是,当我再次单击它们时,按钮仍然起作用.
我在每个事件处理程序方法的开头放置了断点,并单步执行了我的代码.第一次单击时,没有触发任何事件处理程序.在第二声咔哒声中,他们开枪了.
有什么主意吗?
Example of Button Definition (within 100)
public override Control GetAdministrationInterface()
{
// more code...
Button btn = new Button();
btn.Text = "Click Me!";
btn.Click += new EventHandler(Btn_Click);
// more code...
}
Example of Event Handler Method Definition
void Btn_Click(object sender, EventArgs e)
{
// Do Something
}
100 Method that calls 101
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsAsync)
{
List<AdministrationInterface> interfaces = <DATABASE CALL>;
foreach(AdministrationInteface ai in interfaces)
{
placeholderDiv.Controls.Add(ai.GetAdministrationInterface());
}
}
}