title: Wiring up the Page_PreInit event manually, with AutoEventWireup set to false
body: <p>If the <code>AutoEventWireup</code> attribute is set to <code>false</code>, the events need to be wired up manually.  However, I cannot seem to get the <code>Page_PreInit</code> to fire.  I would guess that I might be making the wireup happen too late (once we're already past <code>Page_PreInit</code>), but I'm not sure where else to put the wireups.</p>
  
  <p>For example...</p>
  
  <pre><code>protected override void OnInit(EventArgs e)
  {
      base.OnInit(e)
      PreInit += new EventHandler(Page_PreInit);
      Load += new EventHandler(Page_Load);
  }
  
  protected void Page_PreInit(object sender, EventArgs e)
  {
      Response.Write("Page_PreInit event fired!&lt;br&gt;");  //this is never reached
  }
  
  protected void Page_Load(object sender, EventArgs e)
  {
      Response.Write("Page_Load event fired!&lt;br&gt;");
  }
  </code></pre>
  
  <p>The above code results in "Page_Load event fired!" being displayed, but nothing from <code>Page_PreInit</code>. I tried <code>base.OnInit(e)</code> both before AND after the wireups, and that had no effect.</p>
  
  <p>The graph shown <a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx" rel="nofollow">here</a> says that the <code>OnInit</code> method actually comes after the <code>PreInit</code> event.  With that in mind, I tried overriding <code>OnPreInit</code> and doing the same thing --- no effect.</p>
  
  <p>The MSDN article <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx" rel="nofollow">here</a> explicitly says that in the event of <code>AutoEventWireup</code> set to <code>false</code>, the events can be wired up in an overriden <code>OnInit</code>. The example they use is <code>Page_Load</code>, and of course that works just like it does for me, but they don't address that this doesn't seem to work for the <code>Page_PreInit</code> event.</p>
  
  <p><strong>My question is: how can I get the <code>Page_PreInit</code> event wired up in the case of <code>AutoEventWireup</code> set to <code>false</code>?</strong></p>
  
  <p>I understand there are alternatives as listed on the <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup.aspx" rel="nofollow">MSDN page</a>, such as using the page's constructor.  I'd like to know specifically how to do like they suggest with <code>OnInit</code>.</p>