How to catch an error from a ASCX control

  • Thread starter Thread starter Fernando Chilvarguer
  • Start date Start date
F

Fernando Chilvarguer

I have a very simple test page that the only thing it does is render a
control.

This control generates and throws an error.

I need to catch the error on my ASPX page but I can't figure out where to
put my try/catch block to make it work.

Any ideas?

Thanks,
Fernando
 
Hi,

Fernando said:
I have a very simple test page that the only thing it does is render a
control.

This control generates and throws an error.

I need to catch the error on my ASPX page but I can't figure out where to
put my try/catch block to make it work.

Any ideas?

Thanks,
Fernando

Not tested: The controls are rendered in the Render method of the Page
class. In your own page, which is derived from the base Page class, you
should be able to do that:

protected override void Render( HtmlTextWriter writer )
{
try
{
base.Render( writer );
}
catch ( Exception ex )
{
// Deal with exception
}
}

HTH,
Laurent
 
Hi Laurent,

I tried and it did not work.

By following your example, I tried to handle the exception by putting
similar code on Page_PreInit, Page_Init, Page_PreRender, Page_Load.

Nothing worked.

By stepping into the code, it seems that it was executed in the following
order:

WebPage PreInit, WebPage Init, Control Load (where I throw and exception).

The code still blows up with an "Unhandled Exception"

I guess I'm still confused with the lifecycle and what's calling what on
ASP.NET.
 
Back
Top