UserControl.Error not firing

I have a ASP.NET 2.0 application that implements it's logic in user controls rather then in aspx pages (those are just placeholders). All those user controls inherit from a base user control so I don't have to setup the database connection and stuff like that on every page. So I was coding happily convinced that everything is in order until the database server began to hang repeatedly.
So after some time, we found out that my application is leaving open connections all over the place. I looked at some event handler options that are available in ASP.NET and decided to go with the Error event of a user control. I registered the event, put the database connection closing code in there and continued with my work. And when our tester began to test he application again the server hanged once more.
I started to get suspicious if Microsoft is not telling me something in their documentation, and I asked my friend google. I found nothing unusual about the topic (it could be my occasional bad searching skills). Well I put some tracing code in the Error event handler and I was shocked to find out that the event handler is in fact not getting called (it works fine on a aspx page).
At this time I called my more experienced coworker to help me out. She found an article that confirmed my findings (sorry, no link) and so we started to search for a solution. My coworker eventually suggested that I should register the Error event handler on every page that hosts a user control (in my case I only had to put the code in the base page class) and loop trough child controls and close the connection trough a public method that the user control exposes.
Pretty ugly solution, but it works.
Avtor: Anonymous, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.