1
votes

I am dynamically creating link buttons on user control using a place holder and the eventhandler attached to the link button click+=new Event(Button_Click) is not firing

Thanks in Advance


Code Snippet of

   protected override void OnInit(EventArgs e)
             MenuListPlaceHolder.Controls.Add(new LiteralControl("<li>"));
             ctrl.ID = this.UniqueID + (nCounter++).ToString();
             ctrl.Text = cardType.Name;
             ctrl.Click += new EventHandler(this.CardName_Click);            
             MenuListPlaceHolder.Controls.Add(ctrl);
             MenuListPlaceHolder.Controls.Add(new LiteralControl("</li>"));

When clicked post back event is fired but not executing CardName_Click


1

1 Answers

0
votes

You have to attach it on Page_Load event

like so:

protected void Page_Load(object sender, EventArgs e) {
    this.Btn.OnClick+=new Event(Button_Click) 
}

you should check it: here to learn about page cycle