Signalling events from a class

For easy reference, here’s how to create an event in a class that listeners can react to:

class DeleteSubOrderEventArgs : EventArgs
{
    public int SubOrderId;
    public DeleteSubOrderEventArgs(int subOrderId)
    {
        SubOrderId = subOrderId;
    }
}

class Foobar
{
    public delegate void DeleteEventDelegate(object sender, DeleteSubOrderEventArgs e);
    public event DeleteEventDelegate DeleteSubOrderClick;
    
    protected void DeleteButton_Click(object sender, ImageClickEventArgs e)
    {
        // Signal to listeners
        if (DeleteSubOrderClick != null)
        {
            DeleteSubOrderClick(this, new DeleteSubOrderEventArgs(SubOrder.SubOrderId));
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.