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

后端 未结 5 1887
爱一瞬间的悲伤
爱一瞬间的悲伤 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:04

    When working with dynamic controls, I always add the control in Page_Init, because viewstate loading will happen right after Init. If you add it to Page_Load, there is a chance that you will lose viewstate. Just make sure you provide a unique control ID.

提交回复
热议问题