-1

I don't see the events like Page_Load, Application_Error and all as a overridden methods so that the call can be routed to it from base class. Then how those methods acts like events? Would like to know where the registration of these event happens.

Prasanna
  • 760
  • 2
  • 6
  • 16
  • 1
    http://msdn.microsoft.com/en-us/library/system.web.configuration.pagessection.autoeventwireup(v=vs.110).aspx – Tim Schmelter Jul 26 '14 at 19:02
  • So, when we set autoeventwireup to true, the compiler itself will emit the code for subscribing to the respective events? – Prasanna Jul 26 '14 at 19:06
  • possible duplicate of [What calls Page\_Load and how does it do it?](http://stackoverflow.com/questions/1494543/what-calls-page-load-and-how-does-it-do-it) – Suji Jul 26 '14 at 21:40

2 Answers2

1

Application events and Page events are handled differently. Application is the HttpApplication class while Page is a the Web Forms HttpHandler implementation.

In both cases ASP.NET dynamically generates the event handlers when the ASP.NET compiler is used to parse the initial application using Reflection - when it finds methods with the appropriate prefixes it maps them to the appropriate event handlers. For HttpApplication, these events are hooked up in the HttpRuntime load process and hooked up to the appropriate HttpApplication level events.

I wrote a blog post on the HttpApplication event mapping a while back: http://weblog.west-wind.com/posts/2009/Jun/18/How-do-ASPNET-Application-Events-Work

I can't recall what WebForms does but I believe the overall process is similar: Reflection to pick up Page_ methods and then map them to the underlying events.

Rick Strahl
  • 17,302
  • 14
  • 89
  • 134
0

You can read all about page life cycle here ASP.NET Page Life Cycle Overview .

If you want to catch Application Error event you need to add Global Class. To do this go to VS Solution Explorer point to your Project, right click, select "Add new Item" and then select "Global Application Class". This will create Global.asax with following handlers:

    protected void Application_Start(object sender, EventArgs e)
    {

    }

    protected void Session_Start(object sender, EventArgs e)
    {

    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {

    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {

    }

    protected void Application_Error(object sender, EventArgs e)
    {

    }

    protected void Session_End(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    }
Gregor Primar
  • 6,759
  • 2
  • 33
  • 46