ASP.NET Event Delegation

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Syntax

  1. public delegate void ActionClick();

    public event ActionClick OnResetClick;
    

Remarks

I haven't found any disadvantages in this approach but there are a few things which make this a little problematic.

  1. You need to add an event handler for each and every event. If you do not add the event handlers in the OnInit event of the page, you might face some problems that on page post back, you will lose the event assignment (as ASP.NET is stateless, which is not the case with Windows controls).
  2. In this approach, you need to respect the page life cycle events. Some times when you are working on the Designer, there might be a case when the event handler gets lost without your notice.
  3. Even if you have not added the event handler, you will not get any errors or warnings. If you have multiple pages for performing the same action, there is no guarantee that all the method names will be same; the developer can choose their own method names, which reduces the maintainability of the code.


Got any ASP.NET Question?