0

It seems like there was no such question here before. Where can I find a templated ValidationSummary control? So I could put some html in it: div, h2 inside and a Literal with id="ValidationSummaryMessage" to render text without unnecessary list items, br. Is there any free component in the Internet? I know I could write one for my own, but I'm too lazy for it :-)

Thanks a lot

idm
  • 1,728
  • 2
  • 19
  • 26

1 Answers1

0

One approach would be (even for the lazy ones :-) ) to iterate the validators and create your own Html message from the backend:

StringBuilder myCustomHtml = new StringBuilder();
foreach (Control validator in this.Page.Validators)
{
    IValidator currentValidator = validator as IValidator;
    if (currentValidator != null && !currentValidator.IsValid)
    {
        myCustomHtml.AppendFormat("Bla Foo is missing");
    }
}

Or something like this (haven't tested). It should give you full control, though you should be aware that the control order in Page.Validators is determined by the construction of the control tree during the design. The downside is that a postback is required for this to work.

Another approach would be to capture the event in jquery and add your custom tags and text there.

However, searching SO I found this solution: inherit from asp:validationsummary.

Community
  • 1
  • 1
Olaf
  • 10,049
  • 8
  • 38
  • 54
  • Thank you. One interesting approach that I've found is to collect all error messages in a List and bind them to templated List View control. Now i'm thinking about inheriting from ListView and getting error messages from HttpContext.Current.Validators. Nevertheless, thank you for the answer. – idm Oct 24 '11 at 08:23