473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Tee
what's the differences between "Overrides Sub OnError" and "Sub Page_Error"
?
Nov 18 '05 #1
2 4105
"Tee" <th*@streamyx.com> wrote in message news:eK**************@TK2MSFTNGP11.phx.gbl...
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
Nov 18 '05 #2
Tee
Very nice explanation, Thank you.
"Derek Harmon" <lo*******@msn.com> wrote in message
news:#U**************@TK2MSFTNGP09.phx.gbl...
"Tee" <th*@streamyx.com> wrote in message news:eK**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: gregory_may | last post by:
I have an application I created called "JpegViewer.exe". It simply loads a Jpeg file and displays in on the screen. It works great, in my lab. When I am using it at a customer site, things...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
3
by: Chris Hayes | last post by:
I'm trying to create a nifty Windows Service that will perform tasks at a predetermined interval. To make sure I understand the timing correctly I have set an emailer utility to email me on the...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
6
by: John | last post by:
Hi, Maybe someone can explain the use of "Me" to me? The example class CPoint3 uses the Me reference in the output statement: Console.WriteLine("CPoint3 constructor: {0}", Me) The text states:...
5
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base...
3
by: Arthur Dent | last post by:
Hi all, Im just curious, what is the purpose of the keyword "Overloads" in VB nowadays? I understand conceptually what overloads are and what they do, but im a little puzzled, because if you...
1
by: =?Utf-8?B?QnJldHRWUA==?= | last post by:
I have a child-class that inherits from a base class that implements an Interface. The child class overrides a SUB from the base class that implements a sub from the interface. (The...
1
by: eBob.com | last post by:
I have some code which is trying to determine where text will wrap in a custom text box (which Inherits from Control). It determines the number of characters which will fit in the first line, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.