Click here to Skip to main content
Click here to Skip to main content

ValidationSummary showing header text (HeaderText) only

, 13 Apr 2010
Rate this:
Please Sign up or sign in to vote.
Using the ValidationSummary for validators with ErrorMessage set to needed texts, will always show these ErrorMessage texts when the validation fails.Also, as I noticed, using the ValidationSummary in a long page, will cause an automatic scroll to the first failed field, which is visually...
Using the ValidationSummary for validators with ErrorMessage set to needed texts, will always show these ErrorMessage texts when the validation fails.
 

Also, as I noticed, using the ValidationSummary in a long page, will cause an automatic scroll to the first failed field, which is visually a very good way to guide the user in case of data invalidation. Don't know if this is a crossbrowser feature of the ValidationSummary (never checked Smile | :) ), I only needed for IE so far. So, if you want to make use of this intrinsic effect, you have to use ValidationSummary.
 

It might be the case when you don't want to show all these texts of validators on page, but rather only the HeaderText which could be something generic like "Mandatory fields invalid".
 

 
By default, the ValidationSummary control does not allow that. It will always show the error messages collection from the failed fields.
 

A trick I found out to be working ok, would be to force the ValidationSummary property DisplayMode to "BulletList" and the CssClass to something like "validation_summary_as_bulletlist", where:
 
.validation_summary_as_bulletlist ul
{
    display: none;
}
 

So, the ValidationSummary control would look something like:
 
<asp:ValidationSummary ID="vsSendOrder" ValidationGroup="SendOrder" ShowSummary="true"
CssClass="validation_summary_as_bulletlist" DisplayMode="BulletList" HeaderText="Mandatory fields invalid." runat="server" />
 

This way, the ValidationSummary will always show its HeaderText but will not show the list of ErrorMessage texts from the failed fields.
 

 
Looks like an elegant solution to me, hope you'll find it useful, i'm posting it here because i searched hard to find a solution to this issue, and wasn't able to find one so far Smile | :)
 

 
Again, sorry, I do not know if this solution is crossbrowser functional, hope you'll find out and drop me a note about it Smile | :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

clax70
Software Developer Parazzi AS, Norway
Norway Norway
No Biography provided

Comments and Discussions

 
QuestionGreat Solution. Pinmemberuzzieljv14-Jun-13 9:21 
GeneralGREAT SOLUTION! Pinmemberkarlov9-Aug-12 7:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 13 Apr 2010
Article Copyright 2010 by clax70
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid