Good morning everybody.
I have a question connected with controls and event handling. Lets say I want to create a LinkButton
.
protected
It is important to know how ASP.Net determines which events to invoke. The source of each event is passed using a hidden field:
Whenever the page loads, it pulls in the source of the event from that field and then determines which event to invoke. Now this all works great for controls added through markup because the entire control tree is regenerated on every request.
However, your control was only added once. When a Postback occurs, your control no longer exists as a Server control in the tree, and therefore the event never fires.
The simply way to avoid this is to make sure your Dynamic Controls are added every time the page loads, either through the Page_Init
event, or the Page_Load
event.