UserControl Error event not raised

Discussion in 'ASP .Net' started by Brad, Mar 31, 2005.

  1. Brad

    Brad Guest

    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
    Brad, Mar 31, 2005
    #1
    1. Advertising

  2. 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.)
    Steven Cheng[MSFT], Mar 31, 2005
    #2
    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. Brad
    Replies:
    0
    Views:
    425
  2. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    168
  3. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    178
    vatech1993
    Dec 11, 2004
  4. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    144
  5. NH
    Replies:
    2
    Views:
    512
    Andrew L. Van Slaars
    Dec 17, 2004
Loading...

Share This Page