Sorry if this is a duplicate; I have searched extensively for a basic explanation.
TL;DR - I already know how to wire up events, my question relates to supporting information and event handler naming convention(s), which I cannot find an answer to. Having already read here, here, here, here, and here I think information overload has confused me, or I'm overlooking the obvious.
I have a huge web forms (VB) solution that needs converting to C#, starting with some Web Forms Server Control projects. Within each, VB uses the Handles
word to wire up event handlers:
Public Class Accordion
Inherits CompositeControl
Private Sub Accordion_Init(sender As Object, e As System.EventArgs) Handles Me.Init
End Sub
Private Sub AccordionPanelHolder_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub AccordionPanelHolder_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
End Sub
End Class
When using any kind of code converter, and from my research, the C# approach means manually wiring the event handlers (code shortened for brevity):
public Accordion()
{
PreRender += AccordionPanelHolder_PreRender;
Load += AccordionPanelHolder_Load;
Init += Accordion_Init;
}
private void AccordionPanelHolder_PreRender(object sender, System.EventArgs e)
{
// ...
}
I'm happy with the above, however, if I create a new web form in VS then the default code is simply this:
public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// to do
}
}
There is no event logic handler logic in the page. I see that AutoEventWireUp="True"
, when usually I would have it as False
. My questions therefore:
- What/Where is the naming convention defined that C# uses to auto wire up event handlers, as per the last example? I'm nervous that methods could run twice. I see that VS doesn't have the drop-down functionality for C# to create empty event handlers are that wired up.
- If
AutoEventWireUp="False"
, do I have to manually wire up every single event (I expect so, which is a good thing [I think...])?