Last post Dec 14, 2007 04:22 AM by DMW
Dec 14, 2007 03:16 AM|pipelineconsulting|LINK
Is it possible to throw an exception inside a composite control and have it caught/handled by a validation summary on a web form outside of the control?
E.g. if data were entered into a textbox inside the control, and on postback the text entered was erroneous for whatever reason, the control woudl throw an exception and this exception caught and the message displayed by a validation summary?
Dec 14, 2007 04:22 AM|DMW|LINK
If the control throws an exception in one of its methods, then the page author would have to write an exception handler in the page's method that called that control method. This isn't really tenable.
Your best strategy might be to have a validator inside the composite control to deal with the error - it's ErrorMessage should be picked up by the external ValidationSummary if there is one on the page. Alternatively, throw an exception and let the caller
handle it in the traditional way of displaying an error page (or possibly doing something else in the Page_Error handler).