Search code examples
c#asp.net.netvalidationcustomvalidator

How to show an ASP.NET validation message next to my Save button as well as next to the validated control?


I'm using asp CustomValidator to perform client-side validation on a few controls when the user clicks the Save button on a page. However, this page is quite long so often they can't see the validation message that's displayed next to a control that fails validation. How can I put a general validation message next to the Save button too, e.g. 'Please resolve the validation errors above' so the user knows why the page hasn't submitted?


Solution

  • You can use a Validation Summary control, which you can put near your save button and it will provide a summary of all the validation controls that are invalid.

    You can define it using the following rules:

    <asp:ValidationSummary 
         id="programmaticID" 
         DisplayMode="BulletList | List | SingleParagraph" 
         EnableClientScript="true | false"
         ShowSummary="true | false"
         ShowMessageBox="true | false"                        
         HeaderText="You need to resolve the following issues before you are able to continue:"
         runat="server"/>