Hello All,
Today, I was trying to add a custom validator to my page, as we know that Page.IsValid is responsible to run all validators attached to page. Following Code snippet will create a custom validator on the fly:
In VB:
Dim custom_validate As New CustomValidator() custom_validate.IsValid = False custom_validate.ErrorMessage = "This is dynamic error by server" custom_validate.Display = ValidatorDisplay.Dynamic Page.Validators.Add(custom_validate)
or in c#:
CustomValidator custom_validate = new CustomValidator(); custom_validate.IsValid = False; custom_validate.ErrorMessage = "This is dynamic error by server"; custom_validate.Display = ValidatorDisplay.Dynamic; Page.Validators.Add(custom_validate);
Above code will create a custom validator and add that to page validators.
Best way to show error to centered to page is add a Validation summary and validator’s property display will automatically put error message to validation summary itself.
Any Queries? Let me know.
0 Comments.