Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?

Reply
Thread Tools

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

 
 
Tee
Guest
Posts: n/a
 
      07-09-2004
what's the differences between "Overrides Sub OnError" and "Sub Page_Error"
?


 
Reply With Quote
 
 
 
 
Derek Harmon
Guest
Posts: n/a
 
      07-09-2004
"Tee" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Tee
Guest
Posts: n/a
 
      07-09-2004
Very nice explanation, Thank you.


"Derek Harmon" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> "Tee" <(E-Mail Removed)> wrote in message

news:(E-Mail Removed)...
> > 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Death To Sub-Sub-Sub-Directories! Lawrence D'Oliveiro Java 92 05-20-2011 06:50 AM
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-14-2009 03:51 PM
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-08-2009 04:31 PM
Recognising Sub-Items and sub-sub items using xslt Ben XML 2 09-19-2007 09:35 AM
Differences between getImage and createImage and using Toolkit Thomas Fritsch Java 2 07-27-2006 06:33 AM



Advertisments