AutoEventWireup is an ASP.NET page attribute that will allow automatic wireup of page events when this attribute is set to true on the page. The AutoEventWireup page attribute leads to the following options for the associated VB and C# code-behind class:
AutoEventWireup = true
This allows specifying Page_Load, Page_Init, etc. event handler methods by name alone. In VB, no Handles clause is appended and in C# no event wireup code is required. Provided the method name matches, the methods will automatically handle the associated events. If you do erroneously code any event wireup code, this will cause the event handler to execute twice.
AutoEventWireup = false
This requires that you code the event handler wireup. In VB, you would specify a Handles clause and in C# you would include code to subscribe to the events. However, in C# the problem is that the first page event occurs before the event wireup code has a chance to execute. A common C# approach in this case is to override the base class OnLoad, OnInit, etc. methods, dispensing with the need to have event handler wireup code for the page events. For these cases (Handles used instead of setting AutoEventWireup to true), Instant C# automatically adds event wireups corresponding to all 'Page' methods where a Handles clause is used to the Page_Init or OnInit method if it exists. If no Page_Init or OnInit method exists, a new OnInit method is added. The event wireup for the Page_Init method is added to the class constructor - if no constructor exists, then a constructor is added by Instant C#.
VB.NET and C# Equivalents
Copyright © 1997 – 2019 Tangible Software Solutions, Inc.