UserControl Error event not raised

B

Brad

I added an Error event to a web usercontrol (ascx), but when an error is
raised in the control it does not get called...only the Application_Error
even in the global.asax gets called. The same thing in an aspx works
correctly. Does the Error event not really work with a user control or is
there something I am misunderstanding?
Using Framework 1.1 - VS2003

Thanks


Code Example:
==============================
Public Class WebUserControl1
Inherits System.Web.UI.UserControl

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'bad code which causes an error
Dim x As DataTable
Dim y As DataRow = x.Rows(0)

End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Error
'do something here
'add a debug breakpoint to test error raised.
End Sub
End Class
 
S

Steven Cheng[MSFT]

Hi Brad,

Welcome to ASP.NET newsgroup.
As for the Error event handler of the ASP.NET's UserControl, this seems to
be a existing problem. In fact, the MSDN document hasn't described it
correctly. The UserControl's error handler will not be called when there
occurs unhandled exception during the page's execution. Because the Error
Handler mechanism (like the Page.Error event) is implemented by use a large
try...catch ....

block in the System.Web.UI.Page.ProcessRequestMain function(internal
function), when exception occurs, it will explicitly call the page's error
event handler if exists. However, any other sub control(UserControl)'s
handler won't be detected. The following blog article as also mentioned
this problem:

#The not so clear Error event
http://weblogs.asp.net/vga/archive/2003/06/16/8748.aspx

So currently the only means to intercept the global error is to hook the
Page's Error event or the Application_Error event. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top