Click here to Skip to main content
15,868,039 members
Articles / Web Development / CSS
Tip/Trick

ValidationSummary showing header text (HeaderText) only

Rate me:
Please Sign up or sign in to vote.
3.80/5 (5 votes)
13 Apr 2010CPOL1 min read 23.4K   2
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 :)), 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:

CSS
.validation_summary_as_bulletlist ul
{
    display: none;
}



So, the ValidationSummary control would look something like:

XML
<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 :)



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

License

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


Written By
Software Developer Ajour Software
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGreat Solution. Pin
uzzieljv14-Jun-13 9:21
uzzieljv14-Jun-13 9:21 
GeneralGREAT SOLUTION! Pin
ZioCharles9-Aug-12 7:05
professionalZioCharles9-Aug-12 7:05 

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

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