ASP .NET Web Forms - Why does Visual Studio generate event handlers without parameters for my custom control?

Viewed 57

Why does Visual Studio auto-generate an empty event handler for my custom control, instead of following the usual pattern that takes into account the event delegate itself?

Steps:

  1. Edit aspx page's markup by adding
<foo:MyControl ID="bar" runat="server" OnMyEvent="" />

At the point that I hit = after typing "OnMyEvent", VS behaves as usual by displaying a popup with the option Create new event.

  1. I select this option, but don't see what I would expected to be auto-generated in my code-behind

EXPECTED:

protected void bar_OnMyEvent(object sender, MyEventArgs e)
{

}

ACTUAL:

protected void bar_OnMyEvent()
{

}

My custom control class is:

public class MyEventArgs : EventArgs { ... }

public delegate void MyEventHandler(object sender, MyEventArgs e);

public partial class MyControl : System.Web.UI.UserControl
{
    public event MyEventHandler MyEvent;
    protected virtual void OnMyEvent(MyEventArgs e) => MyEvent?.Invoke(this, e);

    ...

    private void SomethingThatHappens()
    {
        ...
        OnMyEvent(new MyEventArgs(aValue));
    }
}
0 Answers
Related