 |
| 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
|
|
|
|

January 14th, 2004, 01:27 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

January 14th, 2004, 01:44 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What Page Error event are you referring to? That doesn't ring a bell.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 14th, 2004, 05:43 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

January 14th, 2004, 05:49 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

January 15th, 2004, 10:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

January 15th, 2004, 10:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
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.
|
|

January 15th, 2004, 11:13 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

January 15th, 2004, 04:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

January 15th, 2004, 04:42 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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).
|
|
 |