我在页面上嵌套了控件。例如:
Page
-ChildControl1 (of type AllOfMyItems)
-ChildControl2 (of type ListOfItems)
-ChildControl3 (of type MyItem <- this one fires event)
当子控件引发事件时,我希望页面处理该事件。有什么好办法呢?
在这里使用Events and delegates似乎是一个好主意。
所以我试图在我的Page的Page_Init上执行以下操作:
MyItem.SomethingHappened += doStuff();
这是一个很好的方法吗?
答案 0 :(得分:0)
我假设你没有从你的页面直接访问ChildControl2,这就是你的问题。
一个选项是将事件从一个UserControl冒泡到它的父UserControl,依此类推,直到您的页面处理ParentControl.SomethingHappened事件。如果用户控件并不总是像本例中那样嵌套,则建议采用这种方式。