Ever noticed that when you double-click on an ASP.NET UserControl, the code-behind loads, with the cursor in the Page_Load event? Well, this as far as I can tell, is because the UserControl class contains a DefaultEvent attribute, specifying “OnLoad“ as the event. Thus, the VS IDE automatically wires up this event and writes the skeleton code below for you:
private void Page_Load(object sender, System.EventArgs e)
{
}
Problem is, I don't want my UserControls to tell my IDE to do this for me. This is because I generally don't think it makes good design sense to use the Page_Load event from a UserControl. If you've developed ASP.NET apps with multiple controls on a page, you know what I mean. Your app logic may be hiding/showing controls ala Dave Burke's post here. Wheneach UserControl is doing something on Page_Load, things get done too often, and often unnecessarily. Actually, I often delete this method all togtehter. What makes more sense is to have an OnVisible event or what I've done is added a Show() method stub to my UserControlBase class that is intended to handle the initial setup stuff.
So when I double click on the designer panel, I don't want the Page_Load method to be added and wired for me. This is annoying when I've deleted it. One thing I can do is create an Attribute for my base class specifying and “OnVisible” event if I had one or any other event for that matter. But what if I don't want any event wired up? Does anyone know how to keep the IDE from autmatically wiring up events for a class?
-Brendan