Home All Groups Group Topic Archive Search About

How to catch an error from a ASCX control

Author
6 Sep 2006 10:58 PM
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

Author
7 Sep 2006 7:08 AM
Laurent Bugnion
Hi,

Fernando Chilvarguer wrote:
> 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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Are all your drivers up to date? click for free checkup

Author
7 Sep 2006 5:47 PM
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.


Show quoteHide quote
"Laurent Bugnion" <galasoft***@bluewin.ch> wrote in message
news:OYgj1xk0GHA.4796@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> Fernando Chilvarguer wrote:
>> 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
> --
> Laurent Bugnion, GalaSoft
> Software engineering: http://www.galasoft-LB.ch
> Private/Malaysia: http://mypage.bluewin.ch/lbugnion
> Support children in Calcutta: http://www.calcutta-espoir.ch

Bookmark and Share