Matt
Matt

Reputation: 26971

Handling events triggered from controls programmatically added to the page?

I am programatically adding a control to an aspx page and binding a server side event to an index changed event inside the control. (It's a RadListBox from Telerik's ASP.NET controls) The problem is that on the postback triggered from the control, the event doesn't hit its eventhandler because on the postback the control isn't defined.

Is there a way to handle this without having to retrace the logic taken before and rebuild the controls so the events that stem from it are processed?

What is proper way?

Upvotes: 0

Views: 390

Answers (1)

Oded
Oded

Reputation: 498972

You should be adding your dynamic controls in the OnInit event, and add them on every postback.

There is no way for the event of a dynamic control to fire unless the control has been recreated on the postback.

Read about the asp.net page lifecycle.

Upvotes: 2

Related Questions