Crime event

I have a control that has an event handler. I usually used this control on many pages where I control a raised event. But now, as soon as I need to install this control in another control, and then on the page. Is there a way to break an event from the source control?

Normal situation

Control1> Page

Control1

public event EventHandler MyEvent;

protected virtual void OnMyEvent(EventArgs e)
{
   if(this.MyEvent != null) this.MyEvent(this, e);
}

Page.aspx

    <ASP:Control1 id="ctrl1" runat="server" OnMyEvent="ctrl1_MyEvent" />

Page.aspx.cs

    protected void ctrl1_MyEvent(object sender, EventArgs e)
    {
        ....
    }

Exceptional case

Control1> Control2> Page

How can I do to re-raise an event to be managed on the page as described above? Is it possible?

I planned to declare an event handler on the second control again, and then create a method that raises the event, but I was wondering if there was another way to do this.

+4
1

, "SomeNameEventManager".

/ . , (, OnChanged).

:

public class SomeNameEventManager
{
ChangedEventHandler(object sender, EventArgs e);
public static event ChangedEventHandler Changed;
public static void OnChanged(EventArgs e) { Changed(this, e); }
}

, .

, .

+1

Source: https://habr.com/ru/post/1547763/


All Articles