|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to catch an error from a ASCX controlI 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 Chilvarguer wrote: > I have a very simple test page that the only thing it does is render a Not tested: The controls are rendered in the Render method of the Page > 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 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 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
Other interesting topics
ASP.NET 2.0: Global.asax code-behind and web deployment project problem
Disco Not Compiling? GridView - RadioButton for survey, idea needed pass dataset field to an int... Ignore SqlBulkCopy errors VS 2003 & VS 2005 on one machine Calling aspx page from htm file Need bin directory in my web to add httpmodule Column does not belong to table error cannot get value of dropdownlist from postback |
|||||||||||||||||||||||