what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?

Discussion in 'ASP .Net' started by Tee, Jul 9, 2004.

  1. Tee

    Tee Guest

    what's the differences between "Overrides Sub OnError" and "Sub Page_Error"
    ?
     
    Tee, Jul 9, 2004
    #1
    1. Advertising

  2. Tee

    Derek Harmon Guest

    "Tee" <> wrote in message news:...
    > what's the differences between "Overrides Sub OnError" and "Sub Page_Error"


    Overrides Sub OnError is:

    1) faster.
    2) does not require you to write a Handles Page.Error or AddHandler AddressOf( Me.Page_Error).

    However, when overriding OnError, you must begin your Sub with:

    MyBase.OnError( eventArgs)

    Here's the low-down. The ASP.NET Framework will call your Page's (or any ControlTemplate's)
    OnError( ) method when an unhandled exception occurs. By default, the definition of OnError in
    your base class will go through all of the EventHandlers on the Page.Error event (i.e., if you added
    a Handles clause, AddHandler statement, or AutoEventWireup="True", your Page_Error sub would
    be called now).

    Since the Framework automatically calls OnError( ) at the appropriate time, and you have subclassed
    the Page (so you have access to override it, because it is Protected), why go through all the overhead
    of hooking up an event handler? That's why it's faster. But you must remember to call your base's
    OnError( ) if you do it this way, otherwise event handlers that have been hooked-up won't be fired.

    If your code lives outside of the web application's Page subclass, then you cannot override OnError( ),
    and the only way to tap the Page.Error event is to handle it via an AddHandler statement from within
    your external class.


    Derek Harmon
     
    Derek Harmon, Jul 9, 2004
    #2
    1. Advertising

  3. Tee

    Tee Guest

    Very nice explanation, Thank you.


    "Derek Harmon" <> wrote in message
    news:#...
    > "Tee" <> wrote in message

    news:...
    > > what's the differences between "Overrides Sub OnError" and "Sub

    Page_Error"
    >
    > Overrides Sub OnError is:
    >
    > 1) faster.
    > 2) does not require you to write a Handles Page.Error or AddHandler

    AddressOf( Me.Page_Error).
    >
    > However, when overriding OnError, you must begin your Sub with:
    >
    > MyBase.OnError( eventArgs)
    >
    > Here's the low-down. The ASP.NET Framework will call your Page's (or any

    ControlTemplate's)
    > OnError( ) method when an unhandled exception occurs. By default, the

    definition of OnError in
    > your base class will go through all of the EventHandlers on the Page.Error

    event (i.e., if you added
    > a Handles clause, AddHandler statement, or AutoEventWireup="True", your

    Page_Error sub would
    > be called now).
    >
    > Since the Framework automatically calls OnError( ) at the appropriate

    time, and you have subclassed
    > the Page (so you have access to override it, because it is Protected), why

    go through all the overhead
    > of hooking up an event handler? That's why it's faster. But you must

    remember to call your base's
    > OnError( ) if you do it this way, otherwise event handlers that have been

    hooked-up won't be fired.
    >
    > If your code lives outside of the web application's Page subclass, then

    you cannot override OnError( ),
    > and the only way to tap the Page.Error event is to handle it via an

    AddHandler statement from within
    > your external class.
    >
    >
    > Derek Harmon
    >
    >
     
    Tee, Jul 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    0
    Views:
    959
  2. Thomas Fritsch
    Replies:
    2
    Views:
    1,025
    Andrey Kuznetsov
    Jul 27, 2006
  3. Home_Job_opportunity
    Replies:
    0
    Views:
    509
    Home_Job_opportunity
    Jan 8, 2009
  4. Home_Job_opportunity
    Replies:
    0
    Views:
    596
    Home_Job_opportunity
    Jan 14, 2009
  5. Kevin Watkins
    Replies:
    2
    Views:
    186
    Kevin Watkins
    Apr 8, 2004
Loading...

Share This Page