I’m curious about the pros and cons when subscribing to event handlers.
<asp:DropDownList id="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
vs
protected void Page_Init(object sender, EventArgs e)
{
this.DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
}
From the technical point of view, there aren’t any big differences between the two, so it is a question of coding style and personal preferences. Here are a couple of points that you can consider:
In some cases you can use features such as C# lambda expressions nicely in the code-behind:
Something like this can reduce the number of single-purpose event handling methods that you need to write, which should make the code-behind simpler.
However, I think that the general recommendation for simple ASP.NET applications is to use the declarative event handler binding, unless you have some good reason for not doing that (e.g. as in the example above).