事件冒泡到父在ASP.NET [英] Bubbling Events to Parent in ASP.NET

查看:162
本文介绍了事件冒泡到父在ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说这个层次的ASP.NET:

I have say this hierarchy in ASP.NET:

page
  user control 1
     user control 2
         control 3

我希望能够做的是,当控制3(它可以是任何类型的控制,我想一般做到这一点),有用户用它做什么触发回发,它泡了一些事件,用户控制2,甚至可能在用户控件1(虽然我可能有UC 2手动泡沫的情况下也是如此)。

What I want to be able to do is that when control 3 (it could be any kind of control, I want to do this generically) has the user do something with it that triggers a postback, it bubbles up some event to user control 2, or maybe even user control 1 (though I could have UC 2 manually bubble the event too).

此外,我想这样做一般,这样的层次结构可以改变,它仍然有效。也许有多个(对照4等)或数据绑定控件。这可能吗?

Again, I want to do this generically, so that the hierarchy can change and it still works. Maybe there are multiple controls (control 4, etc.) or a data bound control. Is this possible?

感谢。

推荐答案

事件冒泡内置asp.net

Event Bubbling is built into asp.net

检查了这一点:<一href="http://www.4guysfromrolla.com/articles/051105-1.aspx">http://www.4guysfromrolla.com/articles/051105-1.aspx

基本上,提出要冒泡事件:

Basically, to raise the event that you want bubbled up:

RaiseBubbleEvent(this, args);

然后抓住它:

And then to catch it:

protected override bool OnBubbleEvent(object source, EventArgs e) {
    bool handled = false;

    if (e is TemplatedListCommandEventArgs) {
        TemplatedListCommandEventArgs ce = (TemplatedListCommandEventArgs)e;

        OnItemCommand(ce);
        handled = true;
    }
    return handled;
}

由于code意味着,如果该方法返回false,该活动将持续到冒泡的控制层次

As the code implies, if this method returns false, the event will continue to bubble up the control hierarchy

RaiseBubbleEvent的实现   通过控制提供,并且不能   覆盖。 RaiseBubbleEvent发   事件数据最多层次的   控件的父。为了处理或   提高鼓入的情况下,控制   必须重写OnBubbleEvent   方法。

The implementation of RaiseBubbleEvent is provided by Control and cannot be overridden. RaiseBubbleEvent sends the event data up the hierarchy to the control's parent. To handle or to raise the bubbled event, a control must override the OnBubbleEvent method.

从MSDN:<一href="http://msdn.microsoft.com/en-us/library/aa719644(v=vs.71).aspx">http://msdn.microsoft.com/en-us/library/aa719644(v=vs.71).aspx

这篇关于事件冒泡到父在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆