ASP.NET Event Delegation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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?