Adding Custom Validator run-time to your page and throw Data driven Error to page

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

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;

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.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>