Two questions:
On postback when a user clicks submit, how can I add a error message to validation summary?
Is it also possible to highlight a particular textbox using the built in .net validation controls?
asp.netvalidation
Two questions:
On postback when a user clicks submit, how can I add a error message to validation summary?
Is it also possible to highlight a particular textbox using the built in .net validation controls?
Best Answer
Dynamically create a CustomValidator control and add it directly to the Page.Validators collection.
Unlike adding the CustomValidator to the markup, this method allows you to add any number of arbitrary error messages based on server-side business logic.
Note that you can also add it to the page directly, but there are a couple of rules to follow:
You can also create a custom class and implement IValidator, which enables you to add the message with one line of code, but this method doesn't support Validation Groups.
Per Anders Fjeldstad's suggestion, here are a set of handy extension methods.