Instead of having a custom <asp:Label> with the exception from the backend, you can inject a custom error message to the validationsummary of an asp.net page.
Of course, you could use a server-side validator, but that fires everytime you submit the page, and not only after a succesful post. A Custom Validator is therefore in the wrong place.
Here's what I came up with:
public class CustomValidationError : IValidator
{
private string _message;
public CustomValidationError(string message)
{
_message = message;
}
public string ErrorMessage
{
get {
return _message; }set {}
}
public bool IsValid
{
get{ return false; }
set
{
}
}
public void Validate()
{
}
}
To add a custom message to the summary, just do this:
this.Validators.Add(new CustomValidationError("There is no backend!"));
Currently rated 3.5 by 2 people
- Currently 3.5/5 Stars.
- 1
- 2
- 3
- 4
- 5