简体   繁体   中英

Custom asp:Validator that can return multiple ErrorMessages to asp:ValidationSummary

Not sure if this is a silly question or not, but basically what I would like to do is have a single asp:CustomValidator for a password field which returns a list of error messages with the issue encountered during validation.

For example the password may be too short, not complex enough and contain invalid characters.

My hope is that I can set the ErrorMessage field in the validator to contain html which will allow it to render as a bulleted list with a asp:ValidationSummary control. eg ErrorMessage = <li>Password issue 1</li><li>Password issue 2</li> etc...

yuo can add css style to validation summarry..

<asp:validationsummary cssclass="valFailure" runat="server" id="validationSummary">
                </asp:validationsummary>

<style type="text/css">
       .valFailure
       {
           color: #bf1616;
           background-color: #FFBABA;
           border: 3px solid #bf1616;
           font-weight: bold;

       }

       .valFailure ul
       {
           padding-left: 20px;
       }

       .valFailure ul li
       {
           padding-top: 2px;
       }
   </style>

use ValidationSummary control in asp.net

ValidationSummary control allow us to display summary of all validation errors. we can display validation errors summary inline of a web page or a message box or both by using ShowMessageBox and ShowSummary property value true or false. we can display validation messages as bulleted list, single paragraph or only list based on DisplayMode. we can set a header text for validation summary. asp.net validationsummary control have many properties to design the error messages text as like fore color, back color, border color, border style, border width, theme, skin and after all css class.

validationsummary allow to summarize of all validation error messages from all validators in a single location.The following link may help you

http://www.codeproject.com/KB/validation/aspnetvalidation.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM