How to catch an error from a ASCX control

  • Thread starter Fernando Chilvarguer
  • 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
 
L

Laurent Bugnion

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
 
F

Fernando Chilvarguer

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.
 

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