I often get asked things through my messenger and today I decided to start sharing a few lines of the conversations...
Frank:
Is there a way to connect a Validator to an Exception so that the validation summary can be used to display the exception message?
Lennybacon says:
1. build a Custom Validator
Ok
2. Use Page_Error or catch to set a "flag" to the Validator
3. override the method EvaluateIsValid and return the state of the flag
This way the validator (if called on the postback) indicates its validation as true and after the flag is set false.
Here is some pseudo-code
try
{
CriticalOperation();
}
catch(MyException e)
MyValidator.SetInvalid();
MyValidator.ErrorMessage = "bla bla: " + e.Message;
Page.Validate();
Validator : CustomValidator
bool flag = true;
void setInvalid(){flag=false;}
bool EvulateIsValid()
return flag;
http://www.staticdust.net/downloads/Web.ExceptionVisualizer.zip