【发布时间】:2012-09-07 20:48:09
【问题描述】:
这是我设置的结构:
<UserControl1>
<ListView>
<UserControl2 />
<UserControl2 />
<UserControl2 />
<UserControl2 />
</ListView>
</UserControl2>
当用户在 UserControl2 上单击“编辑”时,我想在 UserControl1 上处理该事件。所以我在 UserControl2 上创建了一个事件,在 ListView DataBind 上的 UserControl1 上添加了一个处理程序,并在单击“编辑”时引发了 UserControl2 事件。
但是当用户单击“编辑”时,整个事情都会发回,并且处理程序在 UserControl1 上丢失了。问题是,我无法在每次回发时重新绑定 ListView,因为重新添加处理程序是一项非常繁重且耗时的操作。
那么我怎样才能让 UserControl1 看到 UserControl2 的事件呢?
我尝试过的事情:
- Usercontrol2 上的静态/共享事件...在 asp.net 应用程序上是个坏主意,显然这些静态事件会以某种方式混淆起来,我想它们存在于不同的 web 请求中。
- 将 userControl1 实例属性 (ParentControl1) 添加到 UserControl2...asp.net 中不允许嵌套的 UserControl。
感谢您的帮助。
【问题讨论】: