Stop further execution in Page_Load

G

Gopal Krish

Folks,

My ASPX page uses a custom user control. What happens here is that
when a runtime error occurs in the ASPX page, the error is caught in
the error handler and then strangely, the execution continues to the
custom user control code and it blows there because of the error
occured initially in the ASPX page. When it blows it displays as
unhandled error even though I have try catch in my ASPX page and in
the custom user control.

Is there a way to stop execution if an error occurs in the Page_Load
method and return the contents gathered so far back to the client
(along with the error)?

I tried Response.End and it returns an emppty screen to the client. I
wanted to display whatever has been processed until the point where
the error occured. Pls note this works fine for normal ASPX page but
when I use a custom user control in my ASPX page then the execution
continues to the custom user control code even after an error occured
and caught in my ASPX page's try catch block.

Any thoughts pls?
 
D

Derek Harmon

Gopal Krish said:
Is there a way to stop execution if an error occurs in the Page_Load
method and return the contents gathered so far back to the client
(along with the error)?

I tried Response.End and it returns an emppty screen to the client. I
wanted to display whatever has been processed until the point where
the error occured.

I would answer Response.End as well. The reason you're seeing an empty
screen is because during Page_Load -- that is all the content you have. No
HTML is produced until Render (remember the page lifecycle: Init, Load,
PreRender, Render, and Unload).

If you want your catch statement to remove the offending WebControl(s)
from the Page, so other controls can go on to render, that's one approach
you could use (but you'll also require a way to dynamically put it back in
Page_Init when the situation is repaired, if that's what you're going for).

My suspicion is that you're not catching the exception from the user control,
probably because you have try..catch in the Load events, but not during the
processing wherein ASP.NET calls Render( ) on the Page and your User-
Control. If your Page_Load begins with try and ends with catch, you're
still missing out on the majority of the processing.


Derek Harmon
 
G

Gopal Krish

Thanks Derek. Now I understand the process fully. I think I should be
able to handle it now.

Thanks
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top