How do I attach an event handler to an ASP.NET control created at runtime?

后端 未结 5 1886
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 10:51

Good morning everybody.

I have a question connected with controls and event handling. Lets say I want to create a LinkButton.

protected          


        
5条回答
  •  再見小時候
    2021-01-19 11:12

    That would be because when you click your dynamically generated linkbutton, you do a postback to the server. There you do an entirely new pageload, but your original buttonclick (that generates the link) never happened now, so the linkbutton is never made, and the event can not be thrown.

    An alternative is to add the linkbutton you add dynamically, to your page statically, with Visible = false. And when you click the other button, make it visible.

提交回复
热议问题