简体   繁体   中英

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)
{
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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