Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我以编程方式将控件添加到 aspx 页面并将服务器端事件绑定到控件内的索引更改事件。(它是 Telerik 的 ASP.NET 控件中的 RadListBox) 问题是在控件触发的回发时,该事件不会触发其事件处理程序,因为在回发时未定义控件。
有没有办法处理这个问题,而不必追溯之前采用的逻辑并重建控件以便处理源自它的事件?
什么是正确的方法?
您应该在OnInit事件中添加动态控件,并在每次回发时添加它们。
OnInit
除非在回发中重新创建了控件,否则无法触发动态控件的事件。
阅读有关 asp.net页面生命周期的信息。