display exception one label problem

G

Guest

Hi everyone,
I have a piece of code in sales.aspx.vb like this:
Protected WithEvents Message As System.Web.UI.WebControls.Label
Try
...
ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr + "&ChartType=" +
drpChartType.SelectedItem.Value.ToLower() + "&Print=" +
printVersion.ToString()
...
Catch e As Exception
Message.Text=e.Message
End Try
It handles exception fine before and after the statement:ChartImage.ImageUrl
....
but it seems not being able to catch the exception in ChartGenerator.aspx.vb
Now I am trying to do is handling the exception in ChartGenerator.aspx.vb.
but don't know what to do. with the following code in ChartGenerator.aspx.vb:
try

catch ex as exception
message.text=ex.message
Response.Redirect("ChartGenerator.aspx")
end try
I tried to let the chartGenerator.aspx display the exception using, but it
seems not working. Instead, it displays timeout message from sale.aspx.
Can you shed a light on me?
 
S

Steven Cheng[MSFT]

Hello Betty,

Welcome.

As for the problem you mentioned, my understanding is you have two separate
page, one page(Sales.aspx) use another page(ChartGenerator.aspx) to return
some dynamic image stream and display the image stream through Image
control. However, you found that you can not quite get the exception info
(occured in ChartGenerator.aspx page) in Sales.aspx , correct?

I think this is due to the ASP.NET page model, each page is only displaying
content/text which is writen into its own response stream. And since
sales.aspx and ChartGenerator.aspx are two separate page, they can not be
aware of any exception occured in the other one's processing stage.

For your scenario, I think your current idea on redirect the response
stream is a workable solution. You can catch the exception in the
ChartGenerator.aspx page and then redirect the current request to another
image stream or better a static image file (which display a error screen
message as picture), or you can directly use response.WriteFile to writeout
that static image file (store in your web application's directory. Thus,
in the sales.aspx, the Image control can still get a valid image binary
stream and display the error screenshot.

e.g.

==========================
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Try
If Request.QueryString("fn") = Nothing Then
Throw New Exception("invalid file name....")
End If
Catch ex As Exception

Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.WriteFile(Server.MapPath("~/images/errorinfo.gif"))
Response.End()
End Try

End Sub
============================

the limitation here is that such a static image file can not display
dynamic exception information(callstack, error message....). If you want to
display the error message through image stream, you'd better create a
custom httphandler which dynamically generate image stream(from given text)
and redirect your ChartGenerator.aspx page to that handler. How do you
think of this?

Here are some good articles mentioned creating httphandler to generate
dynamic image stream in asp.net:

#Build an ASP.NET Thumbnail Image Generator
http://www.eggheadcafe.com/articles/20041104.asp

http://davidhayden.com/blog/dave/archive/2005/09/09/2459.aspx

http://www.microsoft.com/belux/msdn/nl/community/columns/desmet/httphandler.
mspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Steve,
Your explanation is very through and it makes perfect sense to me.
I will read article you provided and try to implement it.
You are one of the best among the microsoft discussion forum supports I have
been joined, including sql server discussion forum.
Good night.
 
S

Steven Cheng[MSFT]

Thanks for the quick response.

Glad that the suggsetion is helpful to you and appreciate your feedback:)

Good luck!

Steven Cheng

Microsoft MSDN Online Support Lead


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

Top