收录日期:2020/12/02 23:12:31 时间:2010-09-07 20:22:32 标签:c#,asp.net,postback,autopostback

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?

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.