简体   繁体   English

动态创建的事件处理程序事件未在多视图中触发

[英]Dynamically created eventhandler event is not firing in multiview

I am trying to an add event handler to an image button in one of my view of multi view control. 我试图在我的多视图控件视图之一中向图像按钮添加事件处理程序。 But the event handler is not firing. 但是事件处理程序没有触发。 But if bind the buttons in page load then the event handler is firing. 但是,如果将按钮绑定到页面加载中,则事件处理程序将触发。 Can Anyone help? 有人可以帮忙吗?

LinkButton lnkButton = new LinkButton();
lnkButton.Click += new EventHandler(CButtonClickHandlerNew);

This is how I added the event handler. 这就是我添加事件处理程序的方式。

Use the following code to call the event of dynamically created button 使用以下代码调用动态创建按钮的事件

protected void Page_Load(object sender, EventArgs e)
{
  if(!IsPostBack)
  {
     placeHolder.Controls.Add(CreateButton());
  }  
}

public Button CreateButton()
{
   Button btn = new Button();
   btn.ID = "id";
   btn.Text = "some text";
   btn.Click += btn_Click;
   return btn;
}

private void btn_Click(object sender, EventArgs e)
{
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM