Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2004, 01:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Page Error event

Hello,

I'm a little unfamiliar with the page error event. Does the error event execute when an error occurs outside of a try..catch statement? Does it catch any error regardless of the try..catch event? Do you have to explicitly raise an error with the page object or something of that nature?

Thanks,

Brian Mains
__________________
Brian
 
Old January 14th, 2004, 01:44 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What Page Error event are you referring to? That doesn't ring a bell.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 14th, 2004, 05:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

This is the definition from VS.NET:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles
  MyBase.Error

End Sub
 
Old January 14th, 2004, 05:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It catches and handles any error that occurs in a page and is executed whenever an unhandled exception occurs. You must include Server.ClearError() otherwise the default error generated by the ASP.NET framework would be displayed.

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
        Response.write(Server.GetLastError.Message)
        Server.ClearError()
End Sub


 
Old January 15th, 2004, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm trying to test this process, and I have the following code:
Code:
Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
    Label1.Text = "Error:  " & Server.GetLastError.Message
    Label1.Visible = True
    Server.ClearError()
End Sub

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    Throw New System.Exception("Error occurred")
End Sub
When the link button is clicked, it throws an exception. The page error event catches the error, sets the label to the message of the error and sets the visible property to true, and clears the error. However, the result is a blank page! The html for this page is:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
Why is this happening?

Thanks.
 
Old January 15th, 2004, 10:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Code the server be transferring you to the generic error handling page, but because the error is cleared, it has nothing to show?

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 15th, 2004, 11:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can try this:

Set <customErrors mode="On" /> in the web.config file.
Then at the top of your page add a page directive like this:
<%@ Page ErrorPage="errorpage.aspx" %>

And give a nice user friendly message stating that there was an error while processing your request.


 
Old January 15th, 2004, 04:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I think I will use the web config file to display custom errors. It just seems strange that you can't use the Page error event to trap it also.

Thanks.
 
Old January 15th, 2004, 04:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I got both to work for me although not at the same time.

I do prefer the custom errors page because you can simply say "Site is temporarily down. Please return later". And have the error emailed to you from the global.asax file (application_error).

 
Old January 16th, 2004, 10:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Here is a good article about errors in ASP.NET.

http://www.15seconds.com/issue/030102.htm






Similar Threads
Thread Thread Starter Forum Replies Last Post
Subscribe to event in another control on a page pauliehaha ASP.NET 3.5 Basics 4 July 24th, 2008 03:48 AM
page refresh event shankhan Classic ASP Databases 3 March 29th, 2005 04:16 AM
Grid Page IndexChanged Event not Firing srinuRocks General .NET 1 March 14th, 2005 01:27 AM
Page Load event qadeer05 ASP.NET 1.0 and 1.1 Basics 5 July 19th, 2004 08:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.