I have several server controls that implement the IValidator
interface. As such, they have their own Validate()
methods that look like this.
public void Validate()
{
this.IsValid = true;
if (someConditionFails())
{
ErrorMessage = "Condition failed!";
this.IsValid = false;
}
}
I understand that these Validate()
methods are executed on postback before the load completed event that is executed before the save button's event handler. What I would like to do is pass in a reference to an instance of a custom class that collects all the error messages that I can access from Save button event handler.
In other words, I would like to do something like this:
public void Validate(ref SummaryOfErrorMessages sum)
I guess I can't do this as the signature is different from what the IValidator
interface has. The other option I can think of is on Load Completed event, I would iterate through all the validators on page, get the ones with IsValid = false
and create my SummaryOfErrorMessages
there. Does this sound right? Is there a better way of doing it?