It takes a BIG guy to say – “I don’t know” – and today I am going to say it. There are just too many things about ASP. NET, C# and the world in general that - "I Don't know!"

After coding in .NET ever since it’s first Beta was ever released there are situations like these which are VERY... humbling (spelt - "embarrassing") . We started coding for a project and everything was going fine till we needed to code the PreRender event of a Web Control. 
 
Earlier versions of Visual Studio had Designer Generated Code which looked like -

   39  ///

   40  /// Required method for Designer support - do not modify

   41  /// the contents of this method with the code editor.

   42  ///

   43   private void InitializeComponent()

   44   {   

   45    this.Button1.Click += new System.EventHandler(this.Button1_OnClick);

   46    this.Load += new System.EventHandler(this.Page_Load);

   47   }

Now, if you look at the new Visual Studio.NET 2005 ASP.NET 2.0 Pages this generated code isn't there. My First Instinct was - well, they've hidden it using partial classes and I started looking for another file where I'll be able to see what's going on behind the screens. After spending 10 minutes (literally) I was getting frustrated at my level of know-how of ASP.NET 2.0 works. Turns out, I just couldn't find any partial class or for that matter any line of code where I could see the Page_Load Method being linked to the OnLoad Event! 

After some reading I discovered that Visual Studio.NET 2005 turns AutoWire attribute of forms and web controls to True. Doing this means I'm going to have methods which follow the Object_Event naming pattern. As long as they follow this naming pattern ASP.NET 2.0 will fire (magically) the method when that event for that object occurs.

Long story short you don't need to worry about tying the event to the Method using Event Handler as long as you have AutoWire = true and Your Method follows Object_Event naming convention. This is a little Voodoo'ish  and a little VB6'ish and I'm a little (HIGHLY) embarrassed I didn't know this.

So, we had this concept in VB6 - then in DotNet 1.1 things changed and we spent time learning something new that was done and writing event wiring code. With .Net 2.0 things change again and we spend time again to un-learn what we had learnt with 1.1 and learn what we had already un-learnt when we moved to .NET from VB6. Interesting.

Bottom line is - there are no partial classes hidden for designer generated code in case of ASP.NET pages. In fact, there is practically no generated code for Event wiring in ASP.NET 2.0 - it's the “AutoWrite = true” that is doing the Magic! That essentially means that if I wanted to code for PreRender Event in a Web Control - I just start writing the following code on the Control's Code behind and don't worry about the event wiring at all. Cool!

   20    protected void Page_PreRender(object sender, EventArgs e)

   21     {

   22         Response.Write("This is The PreRender Event Of the Control");

   23     }